2. Interacting With MATLAB

 

2.1           Using MATLAB’s windows

2.2           Using the Command window

2.3           Writing tiny programs in the Command window

2.4           Allowing or suppressing outputs by omitting or including end-of-line semi-colons

2.5           Editing, saving, and running program scripts (.m files)

2.6           Running and debugging programs

2.7           Keeping a diary

2.8           Practicing interacting with MATLAB

 

top of page

2.3 Writing tiny programs in the command window

 

 

Code 2.3.1:

 

A = 2

 

Output 2.3.1:

 

A =

 

     2

 

 

Code 2.3.2:

 

2 = A

 

Output 2.3.2:

 

??? 2 = A

     

Error: The expression to the left of the equals sign is not a valid target for an assignment.

 

 

 

Code 2.3.3:

 

A

 

Output 2.3.3:

 

A =

 

     2

 

 

 

Code 2.3.4:

 

a

 

Output 2.3.4:

 

??? Undefined function or variable 'a'.

 

 

Code 2.3.5:

 

a = 3

 

Output 2.3.5:

 

a =

 

     3

 

Code 2.3.6:

 

My_Difference = a - A

 

Output 2.3.6:

 

My_Difference =

 

     1

 

 

Code 2.3.7:

 

for = 4

 

Output 2.3.7:

 

??? for = 4;

        |

Error: The expression to the left of the equals sign is not a valid target for an assignment.

 

 

Code 2.3.8:

 

a + A

 

Output 2.3.8:

 

ans =

 

     5

 

 

Code 2.3.9:

 

ans

 

Output 2.3.9:

 

ans =

 

     5

 

 

 

top of page

2.4  Allowing or suppressing outputs by omitting or including end-of-line semicolons

 

Code 2.4.1:

 

My_Difference;

 

Output 2.4.1:

 

>> 

 

 

Code 2.4.2:

 

My_Difference_2 = A - My_Difference;

 

Output 2.4.2:

 

>> 

 

 

Code 2.4.3:

 

My_Difference_2

 

Output 2.4.3:

 

My_Difference_2 =

 

     1

 

 

 

top of page

2.5 Editing,  Saving, and Running MATLAB Programs

 

 

Code 2.5.1:

 

% My_Program_01

 

% A program to add two numbers called X and Y.

 

X = 10;

Y = 12;

 

Z = X + Y

 

% end of program

 

 

Output 2.5.2:

 

Z =

 

     22

 

 

Code 2.5.1:

 

% Ellipsis_Illustration

 

Method_1_Score_1 = 899;

Method_2_Score_1 = 1286;

 

Method_1_Score_2 = 1018;

Method_2_Score_2 = 1344;

 

Method_1_Score_3 = 1167;

Method_2_Score_3 = 1389;

 

Summed_Differences_Between_Method_2_and_Method_1_Scores = ...

Method_2_Score_1 - Method_1_Score_1 + ...

Method_2_Score_2 - Method_2_Score_2 + ...

Method_2_Score_3 - Method_1_Score_3

 

Output 2.5.2:

 

Summed_Differences_Between_Method_2_and_Method_1_Scores =

 

   609