Plot multiple graph using 'hold on' and loop function

조회 수: 1 (최근 30일)
Shuvayan
Shuvayan 2013년 1월 25일
Hi everyone. I am trying to plot multiple graph in Matlab. The equation is power law y=ax^n. The value of "n" varies from 0.1 to 1 and value of "a" also varies and accordingly y is calculated by varying x. The code i have written is below. Please suggest any solutions.
n=0.1:0.1:1;
x=0.1:0.1:3;
while (n<1.1)
a=1/3^n;
y=a*x.^n;
plot (x,y)
hold on
n=n+0.1;
x=x+o.1;
end

답변 (2개)

Evgeny Pr
Evgeny Pr 2013년 1월 25일
You want to do this?
n = 0.1:0.1:1;
x = 0.1:0.1:3;
for ni = n
a = 1 / 3^ni;
y = a * x.^ni;
plot (x, y)
hold on
end

José-Luis
José-Luis 2013년 1월 25일
n=0.1:0.1:1;
x=0.1:0.1:3;
[X N] = ndgrid(x,n);
A = (1/3).^N;
Y = A.*X.^N;
plot(X,Y);

카테고리

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