Introduction to MATLAB Michael Fink [email protected]• Login and press the Matlab icon • Part 1: Using vectors and matrices • Part 2: Performing calculations • Part 3: Programming basics • Part 4: Visualization (graphs) • Part 5: Functions & function handles
Introduction to MATLAB Michael Fink [email protected]. Login and press the Matlab icon Part 1: Using vectors and matrices Part 2: Performing calculations Part 3: Programming basics Part 4: Visualization (graphs) Part 5: Functions & function handles. Introduction to matlab. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
• Part 1: Using vectors and matrices• Part 2: Performing calculations• Part 3: Programming basics• Part 4: Visualization (graphs)• Part 5: Functions & function handles
case '*', finalVal=str2num(inChar(1:i-1))*str2num(inChar(i+1:end)); break case '/', if str2num(inChar(i+1:end))==0 okInput = false; else finalVal=str2num(inChar(1:i-1))/str2num(inChar(i+1:end)); break end otherwise i=i+1; endendif okInput, disp(['is ' num2str(finalVal)]);else 'div by 0!'end
Copy paste into myscript.m and
press F5
Visualization: plots
figure(1);x = -5:0.1:5; y = cos(x); plot(x,y)hold on;y2 = sin(x); plot(x, y, 'm', x, y2, 'g.');axis([-2*pi 2*pi -1 1]);axis tight;
Visualization: images% display noisy matrix
clf;
imagesc(randn(10));
title('noisy x');
axis square;
Language elements: functions• Functions are called externally with some input,
use their own variables and return an output
• Several functions could be defined in a single file but only the heading function (with the same name as the file) will be available externally
Function handlesfunctions as variables: efficient when different functions need to be used in the same way
a=0; b=pi/2; dt=0.001;for i=1:3 switch i case 1, f1=@sin; case 2, f1=@sqrt; case 3, f1=@myfunc; end ff = f1([a:dt:b]); ['integral = ' num2str(sum(ff*dt))]end
Matlab is endless
• Linear algebra– det (matrix determinant)– eig (eigenvalues and get eigenvectors)
• Optimization toolbox– Linear / quadratic programming