フィルターのクリア

How to plot using a loop on the same axis

1 回表示 (過去 30 日間)
Tebogo Makobe
Tebogo Makobe 2021 年 8 月 14 日
コメント済み: Tebogo Makobe 2021 年 8 月 14 日
Would like to plot without having to hard code every single line up to 20+ customers(20 x 1 structure). Had an attempt at a for loop, the error message states that the number of element on the right are not same as on the left
%Graphical representation
t = 0:0.1:310; % Time vector for plots (m)
[position1,speed1,Duration1] = calcFallForPerson(customer(1),4200,0.1,1500);
[position2,speed2,Duration2] = calcFallForPerson(customer(2),4200,0.1,1500);
[position3,speed3,Duration3] = calcFallForPerson(customer(3),4200,0.1,1500);
[position4,speed4,Duration4] = calcFallForPerson(customer(4),4200,0.1,1500);
figure(1)
plot(t,position1,t,position2,t,position3,t,position4)
title('Posiion')
xlabel('Time(s)')
ylabel('Postion(m)')
xlim([0 320])
ylim([0 4500])
figure(2)
plot(t,speed1,t,speed2,t,speed3,t,speed4)
title('Velocity')
xlabel('Time(s)')
ylabel('Velocity(m/s)')
xlim([0 320])
ylim([0.0 60.0])
xlim([0 320])
ylim([0.0 60.0])

採用された回答

Wan Ji
Wan Ji 2021 年 8 月 14 日
Is the time array t the same size as position1,speed1 for each loop with different customers? If so, then following loop will help you!
t = 0:0.1:310; % Time vector for plots (m)
number_of_customer = 20; % change as you want
[position,speed,Duration] = arrayfun(@(i)acalcFallForPerson(customer(i),4200,0.1,1500),...
1:1:number_of_customer, 'uniform', false);
figure(1)
arrayfun(@(i)plot(t,position{i}),1:1:number_of_customer);
title('Posiion')
xlabel('Time(s)')
ylabel('Postion(m)')
xlim([0 320])
ylim([0 4500])
figure(2)
arrayfun(@(i)plot(t,speed{i}),1:1:number_of_customer);
title('Velocity')
xlabel('Time(s)')
ylabel('Velocity(m/s)')
xlim([0 320])
ylim([0.0 60.0])
xlim([0 320])
ylim([0.0 60.0])
  1 件のコメント
Tebogo Makobe
Tebogo Makobe 2021 年 8 月 14 日
Thanks will try it out.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by