Documente Academic
Documente Profesional
Documente Cultură
ahera @wpi.edu
- 2013-
MATLAB Course
2. Variables;
3. Operators; 4. Matlab functions; 5. Matrices; 6. Scripts; 7. Basic plotting. 8. User Defined Functions 9. Importing Data
10. Simulink
11. Flow Control Commands
2
The plot function has different forms, depending on the input arguments.
If y is a vector, plot(y) produces a piecewise linear graph of the elements of y versus the index of the elements of y. If you specify two vectors as arguments, plot(x,y) produces a graph of y versus x.
3
s
b g r c m y k blue green red cyan magenta yellow black
. o x + * s d .
: -. --
(none) no line
plot (x,y,'c+:')
Matlab - Plotting
clear t=0:0.01:10; % time seconds signalSin=sin(2*pi*t); % signal1 - frequency =1 Hz signalCos=0.5*cos(2*pi*t); % signal2 - frequency =1 Hz figure plot(t,signalSin); hold on plot(t,signalCos, '-*r'); xlabel('time'); ylabel('signal'); legend('Sin', 'Cos'); title('Two Signals','FontSize',12)
plot2signals.m
Other commands:
Matlab - Plotting
Two Signals
1 0.8 0.6 0.4 0.2 Sin Cos
signal
5 time
10
Visualization - subplot
>> subplot(3,1,1)
1 0.5
0.8
>> subplot(1,3,1)
1
0.2
0.4
0.6
0.8
1
0.6
0.4
0.2
0.5
>> subplot(3,2,4) 1
1
2 4
0 0.5 1
plot3Windows.m
5 6
8
Visualization - subplot
clear; % clear the workspace close; % close previous figures
SignalSin 1
signal3=signalSin.*signalCos;
0.5
signal
-0.5
title('SignalSin')
0 1 2 3 5 6 time(s) Product of two signals 4 7 8 9 10
xlabel('time(s)');
ylabel('signal');
0.2
signal
0 -0.2 0 1 2 3 4 5 time(s) 6 7 8 9 10
plot3Windows.m
10
dlmread , dlmwrite
xlsread, xlswrite fopen, , fscanf, fprintf
11
prepareData.m
fileName
data=dlmread(myFile);
matrix to be saved
Delimiter = tab
data=dlmread('dataCSV.csv', ',',2,0);
dlmread reads from the ASCII-delimited numeric data file filename to output matrix M. The delimiter separating data elements is inferred from the formatting of the file.
Comma (,) is the default delimiter.
13
14
To import Excel data by wizard (uiimport) the file should have the extension .xls
15
Fourier Transform
MATLAB provides a collection of functions for computing and working with Fourier transforms.
Y = fft(X)
returns the discrete Fourier transform (DFT) of vector X, computed with a fast Fourier transform (FFT) algorithm.
Other related commands: fft(X,N) is the N-point FFT ifft, abs, angle, unwrap HT hilbert transform myHT.m
16
17
Fourier Transform
Other related commands: fft(X,N) is the N-point FFT ifft, abs, angle, unwrap HT hilbert transform myHT.m
18
>> wintool
19