Applied Electromagnetics Using Quickfield & MATLAB

Appendix 1: A Walk Through MATLAB

M-FILES

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.

Basic Math and Syntax

% 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

Logical Operators

~ % not % or& % and

Conditionals

if condition   operations;end;if condition   operations1;else   operations2;end;if condition1   operations1;elseif condition2   operations2;else    operations3;end;

Loops

for i=1:n         ...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: SCR Power Controllers
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.