Unrecognized function or variable 'del'.

조회 수: 1 (최근 30일)
Kaustubh Joshi
Kaustubh Joshi 2024년 6월 10일
편집: Aquatris 2024년 6월 10일
n=0;
>> for del=0.0:0.4:pi
n=n+1;
pe(n)=1.2*sin(del);

답변 (3개)

ScottB
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.

Aquatris
Aquatris 2024년 6월 10일
편집: Aquatris 2024년 6월 10일
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
del = 0
del = 0.4000
del = 0.8000
del = 1.2000
del = 1.6000
del = 2
del = 2.4000
del = 2.8000

Star Strider
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
Elapsed time is 0.026322 seconds.
pe
pe = 1x8
0 0.4673 0.8608 1.1184 1.1995 1.0912 0.8106 0.4020
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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
Elapsed time is 0.002461 seconds.
pe
pe = 1x8
0 0.4673 0.8608 1.1184 1.1995 1.0912 0.8106 0.4020
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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
Elapsed time is 0.001995 seconds.
pe
pe = 1x8
0 0.4673 0.8608 1.1184 1.1995 1.0912 0.8106 0.4020
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
The vectorisation approach is morst efficient in this instance (and likely others as well).
See the documentation section on Vectorization for details.
.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by