Plots using for loops

조회 수: 13 (최근 30일)
Zoe Westcott
Zoe Westcott 2022년 6월 10일
댓글: Zoe Westcott 2022년 6월 10일
This is my text, i want do a loglog plot for error which is my function Ptoject_example3 against h, but wheneber I run the code doesnt plot anything.
m=1;
for h=0.01:0.01:0.1
error = Project_example3(h,m);
end
h=0.01:0.01:0.1;
figure;
loglog(error,h)

채택된 답변

KSSV
KSSV 2022년 6월 10일
편집: KSSV 2022년 6월 10일
Your code saves, only one value for error, which happens to be the last value of the loop. You need to save error into an array and then plot.
m=1;
h=0.01:0.01:0.1;
error = zeros(size(h)) ;
for i = 1:length(h)
error(i) = Project_example3(h(i),m);
end
figure;
loglog(error,h)
  댓글 수: 1
Zoe Westcott
Zoe Westcott 2022년 6월 10일
Thank you, helped very much

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by