Unrecognized function or variable 'del'.
2 ビュー (過去 30 日間)
古いコメントを表示
n=0;
>> for del=0.0:0.4:pi
n=n+1;
pe(n)=1.2*sin(del);
0 件のコメント
回答 (3 件)
ScottB
2024 年 6 月 10 日
del is a native function:
Try renaming your variable. You also need and "end" statement at the end of your loop.
0 件のコメント
Star Strider
2024 年 6 月 10 日
That should actually work —
tic
n = 0;
for del=0.0:0.4:pi
n=n+1;
pe(n)=1.2*sin(del);
end
toc
pe
A mnore efficient implementation would be —
tic
del=0.0:0.4:pi;
for n = 1:numel(del)
pe(n) = 1.2*sin(del(n));
end
toc
pe
However you can take advantage of MATLAB vectorisation capabilities and just use —
tic
del=0.0:0.4:pi;
pe = 1.2*sin(del);
toc
pe
The vectorisation approach is morst efficient in this instance (and likely others as well).
.