Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Plotting using a for loop

2 ビュー (過去 30 日間)
Fraser Brooker
Fraser Brooker 2020 年 10 月 26 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I'm having trouble with plotting a graph when using a for loop to generate the values.
x = 0: 0.1 : 1.4
for x = 0:0.1:1.4
y = iteration2shear(x)
end
plot(x,y)
hold on
The function I'm calling generates the correct values for each value of y, but im struggling to generate a plot to illustrate it.

回答 (2 件)

Rik
Rik 2020 年 10 月 26 日
You are forgetting to index your y variable. In general it is easier to write your code like this in such cases:
x = 0: 0.1 : 1.4;
y=zeros(size(x));
for n=1:numel(x)
y(n) = iteration2shear(x);
end
plot(x,y)

Jon
Jon 2020 年 10 月 26 日
You need to save your values to a vector you are just replacing a single scalar value
  1 件のコメント
Jon
Jon 2020 年 10 月 26 日
I see that by the time I answered your question Rik had also given you a good answer

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by