Unrecognized function or variable 'del'.
Show older comments
n=0;
>> for del=0.0:0.4:pi
n=n+1;
pe(n)=1.2*sin(del);
Answers (3)
ScottB
on 10 Jun 2024
0 votes
del is a native function:
Try renaming your variable. You also need and "end" statement at the end of your loop.
Not recommended but you can generally overwrite native variable/function names. I cannot reproduce your problem
n = 0;
for del=0.0:0.4:pi
n=n+1;
pe(n)=1.2*sin(del);
del % disp
end
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).
.
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!