フィルターのクリア

very strange error of for loop

5 ビュー (過去 30 日間)
NoYeah
NoYeah 2020 年 4 月 16 日
コメント済み: Star Strider 2020 年 4 月 16 日
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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by