How to make this code more efficient?

1 回表示 (過去 30 日間)
suleiman abdullahi
suleiman abdullahi 2020 年 9 月 26 日
コメント済み: suleiman abdullahi 2020 年 9 月 27 日
I am new to MATLAB hence my poor use of it as you can see in this piece of code. I think a for loop would be handy here, so any help is appreciated.
% these are four time series to plotted against a set of signal data shown as accVert, accLat and accLong
newTime1 = (time >= 8 & time <= 11) ; % select data of specific time
newTime2 = (time >= 81 & time <= 86) ;
newTime3 = (time >= 124 & time <= 128) ;
newTime4 = (time >= 167 & time <= 172) ;
figure(3),clf(3)
subplot(2,2,1)
plot(time(newTime1),[accVert2(newTime1),accLong2(newTime1),accLat2(newTime1)],'linewidth',1.2)
xlabel('time, s')
ylabel('acceleration m/s^2')
title('acceleration at t = 8s and t = 12s')
subplot(2,2,2)
plot(time(newTime2),[accVert2(newTime2),accLong2(newTime2),accLat2(newTime2)],'linewidth',1.2)
xlabel('time, s')
ylabel('acceleration m/s^2')
title('acceleration at t = 81s and t = 86s')
subplot(2,2,3)
plot(time(newTime3),[accVert2(newTime3),accLong2(newTime3),accLat2(newTime3)],'linewidth',1.2)
xlabel('time, s')
ylabel('acceleration m/s^2')
title('acceleration at t = 124s and t = 128s')
subplot(2,2,4)
plot(time(newTime4),[accVert2(newTime4),accLong2(newTime4),accLat2(newTime4)],'linewidth',1.2)
xlabel('time, s')
ylabel('acceleration m/s^2')
title('acceleration at t = 167s and t = 172s')
  5 件のコメント
Walter Roberson
Walter Roberson 2020 年 9 月 26 日
Using a for loop could make the code more compact. However, it would only have a very small effect on code execution, due to the marginally faster parsing of slightly fewer lines of code. That marginally faster parsing in turn might be offset by the need to dynamically create the titles. The difference is not going to be large.
suleiman abdullahi
suleiman abdullahi 2020 年 9 月 27 日
Thanks all for the suggestions. I would try to improve on Chris's points.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by