Applied Electromagnetics Using Quickfield & MATLAB

M-files are fun and easy to use. In many cases it is better create an M-file when writing code blocks more than a few lines in length. The M-file is saved under a filename such as 'chua_circuit.m' M-files are much easier to edit than code entered in the Command Window. After code is executed in the Command Window, it is necessary to use the Up Arrow on the keyboard to bring up a given line to modify/correct it.
To create an M-file select (File ? New ? M-file) then enter the code and save the file (File ? Save as ? filename.m)
As an example, consider the M-file consisting of the code block
1+1
saved as 'sally.m.' The M-file is executed in the Command Window by typing 'sally' at the Command Prompt
>> sally
resulting in the output
ans = 2
Try creating M-files with some of the graphing examples below.
% comment; output suppression<span class="beginpage"> pagenum="378"><a name="1106"></a><a name="IDX-378"></a></span>3+2-4*2-2/3 % addition, subtraction, multiplication, division3^2 % exponentiationsqrt(9) % square root
~ % not % or& % and
if condition operations;end;if condition operations1;else operations2;end;if condition1 operations1;elseif condition2 operations2;else operations3;end;
for i=1:n ...