%This is an example of how to use Matlab. %This is a comment %This is a bunch of simple math statements: a = 2. %If you do not put a semi-colon after the statement, the result will %be printed to the screen when you run the program. b = 3.; %If you put a semi-colon after the statement, the result will not be %printed to the screen when you run the program. c = a+b d = a*pi; %pi is a preset value in matlab, Note that d is not printed out when you run your program e = cos(a*pi)/b %When you need help on something in matlab, go to the main matlab menu, %and type "help cos" (for instance -- this will get you help on the cosine function) %Here is a loop that creates a list of even integers from 2 to 200 for i=1:100; %for loops and array indices must start with a number greater than zero array(i) = i*2; % be sure to put a semicolon here, or a big list will be printed to the screen! end %This finds the maximum of the array array_max = max(array) %This tells you how large the array is size(array) %This plots the array plot(array) %Figure 1 %This sets up two arrays and plots them against eachother for i=1:100; x(i) = i; y(i) = i*i; end figure; %open a new figure so you don't overwrite the old one plot(x,y); %Figure 2 %If statement, greater than or less than: if (a <= b) c=5; %(if a is less than or equal to be, set c equal to 5) %You can also make a polar plot figure; polar(x,y); %Here is a 2D color plot for i=1:100; for j=1:100; array2d(i,j) = i+j; end end figure; %Figure 3 pcolor(array2d); %To plot several plots on the same graph: figure; %open a new figure plot(array); %Figure 4 hold; %Hold existing figure plot(x,y); %Figure 5 %plot another graph on the same figure %OR figure; plot(x,y,'r');hold;plot(array*2,'b'); %Figure 6 % r = red, b=blue, y=yellow, g=green, k=black % You can also use different line types and symbols figure; plot(x,y,’r.’);plot(array*2,’b-‘); %Labels and Titles (use help as needed) title('This is the Title') xlabel('This is the x-axis') ylabel('THis is the y-axis') %gtext('Put something here') %This uses the cursor to place text on the figure %(uncomment it to try it out) %legend(‘onething’,’anotherthing’,etc.) creates a legend box for each line in %your plot. It automatically uses the same line types and colors as are in the %plot.