How to plot this for loop?

조회 수: 1 (최근 30일)
Nick Kavouris
Nick Kavouris 2020년 10월 11일
답변: Ameer Hamza 2020년 10월 11일
for i=0:0.01:1;
CompMod=(Gmodulus*i)+(Emodulus*(1-i));
end
plot(i,CompMod)
How do I plot this simple code? Gmod and Emod have been previously indexed

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 11일
You need to save the values from each iteration in an array. Check this code
Gmodulus = 1; % example values
Emodulus = 2;
x = 0:0.01:1;
CompMod = zeros(size(x));
for i = 1:numel(x)
CompMod(i) = (Gmodulus*x(i))+(Emodulus*(1-x(i)));
end
plot(x,CompMod)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by