For loop error: Subscript indices must either be real positive integers or logicals

1 回表示 (過去 30 日間)
I am executing a for loop but it gives following error at time 0.6:
T_o=[0;0;0];
T_d=[0;0;0];
T_l=[0;0;0];
out_n=zeros([],3);
for t=0:0.1:10
T_o = [0.05*(10-t);0.04*(10-t);0.03*(10-t)];
T_e=T_d-T_o;
T_e=[t*10 T_e'];
a = sim('PD_control','SimulationMode','normal');
out = a.get('T_u');
out_n(t*10+1,:) = out(2,:)
end
The Simulink file called by this code is attached here.

採用された回答

KSSV
KSSV 2019 年 7 月 12 日
T_o=[0;0;0];
T_d=[0;0;0];
T_l=[0;0;0];
out_n=zeros([],3);
tt=0:0.1:10 ;
for i = 1:length(tt)
t = tt(i) ;
T_o = [0.05*(10-t);0.04*(10-t);0.03*(10-t)];
T_e=T_d-T_o;
T_e=[t*10 T_e'];
a = sim('PD_control','SimulationMode','normal');
out = a.get('T_u');
out_n(i,:) = out(2,:)
end

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 7 月 12 日
mat2str((find((0:0.1:10)*10-(0:100))-1)/10)
0.3 0.6 0.7 1.2 1.4 2.3 2.4 2.8 2.9 4.1 4.6 4.8 5.2 5.4 5.9 6.2
That is, 0.3 * 10 is not 3.0 exactly.
0.1 in binary floating point is not exactly 1/10, just the same way that in decimal 0.333...3 * 3 is 0.999...9 instead of 1

カテゴリ

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

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by