Plotting the integral of a graph

191 Ansichten (letzte 30 Tage)
Hans123
Hans123 am 4 Dez. 2019
Kommentiert: Fabio Freschi am 4 Dez. 2019
Hi,
I have a graph of a waveform that I want to find the integral plot of this waveform (shown below). Could this be done on MATLAB or is this something for Simulink. I am new to Simulink, and I would appreciate any help on graphing the integral plot.

Akzeptierte Antwort

Fabio Freschi
Fabio Freschi am 4 Dez. 2019
Suppose that x and y are the vectors defining your waveform.
% dummy values
x = linspace(0,2*pi,1000);
y = sin(x);
% integral
Y = cumtrapz(x,y);
% plot
figure, hold on
plot(x,y); % waveform
plot(x,Y); % integral
legend('waveform','integral')
  2 Kommentare
Hans123
Hans123 am 4 Dez. 2019
thank you Fabio! I just want to verify the plot I got is the integral - what would be the code to derive Y so I could plot it and verify it is the same as the initial plot.
Fabio Freschi
Fabio Freschi am 4 Dez. 2019
My pleasure! The derivative can be obtained with diff function.
yd = diff(Y)./diff(x);
% yd has one point less, so we must calculate an ad-hoc x vector
xd = (x(1:end-1)+x(2:end))/2;
% plot
plot(xd,yd);
It this solves your original question, please accept it!
F

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by