How can I plot the integration result?

2 ビュー (過去 30 日間)
Muhammad Hadyan Utoro
Muhammad Hadyan Utoro 2021 年 6 月 21 日
コメント済み: Star Strider 2021 年 6 月 21 日
I used loop to do an integration to get velocity and position, but when I want to plot them, it showed error:
Error using plot
Vectors must be the same length.
Error in Droptest (line 30)
plot(time, V, 'm--')
Here is script I used:
%% Deformation Velocity
for i = 1:length(time)-1;
j = 1:length(xaccel)-1;
V0 = 0;
V = V0 + (xaccel(j+1)+xaccel(j)/2)*(time(i+1)-time(i));
end
I can't figure it out how to make them the same length and using the iterative at the same time.
I appreciate your help

採用された回答

Star Strider
Star Strider 2021 年 6 月 21 日
If you want to plot the cumulative acceleration to get velocity and position, use the cumtrapz function:
t = linspace(0, 10); % Create Data
xaccel = exp(-0.25*t) .* sin(2*pi*t/10); % Create Data
xveloc = cumtrapz(t, xaccel); % Integrate
xposit = cumtrapz(t, xveloc); % Integrate
figure
plot(t, xaccel)
hold on
plot(t, xveloc)
plot(t, xposit)
hold off
grid
legend({'Acceleration','Velocity','Position'}, 'Location','best')
.
  2 件のコメント
Muhammad Hadyan Utoro
Muhammad Hadyan Utoro 2021 年 6 月 21 日
Thank you so much for your help! I really appreciate that
Star Strider
Star Strider 2021 年 6 月 21 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by