very strange error of for loop

2 次查看(过去 30 天)
I made this kind structure code
but the result is not I had expecetd
k=1;
for i=1:1:100
if(i==1)
a=zeros(size(i));
b=zeros(size(i));
end
a(k)=sin(i);
b(k)=a(k)
k=k+1
end
a(k) display the sin wave
but b(k) dispay only one constant value
like y=3
what happend to my code?

采纳的回答

Star Strider
Star Strider 2020-4-16
You did not include the plot call you are using.
If you are plotting:
figure
plot(a,b)
it will show a straight line from (-1,-1) to (1,1) because both ‘a’ and ‘b’ have the same values.
.
  2 个评论
NoYeah
NoYeah 2020-4-16
yes it has to be same
but my code they are not the same
werid
Star Strider
Star Strider 2020-4-16
I am using R2020a, and Windows 10.
Is that the only code you are running in that script?
There could be version differences, however I doubt they would be that extreme.
If you run this line:
which plot -all
from your Command Window or a script, all the results should share this part of the path to each (the exact configuration could be operating-system dependent):
C:\Program Files\MATLAB\R2020a\toolbox\matlab\
The rest oif the path will likely vary. If any do not, and it turns out that you have another function named ‘plot’, that could be the problem. (Naming user-defined functions the same as MATLAB built-in functions is called ‘overshadowing’ and is to be avoided.)
Beyond that, I have no idea what the problem could be.
.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by