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