How can I plot with a for data named h1-h10?

조회 수: 3 (최근 30일)
Michael
Michael 2022년 4월 11일
댓글: Voss 2022년 4월 11일
I have some data named h1,h2,....,h10. I want to plot them seperately in different figures. I have done this and it does not work, which I think is because of an incorrect way of using num2str. What can I do to correct it?
x=-0.21:0.01:0.21;
h=0.098;
L=0.447;
g=9.81;
for i=1:1:10
j=num2str(i);
figure
parabola=h+omegah(i)^2/(2*g)*(x.^2-L^2/12);
plot(x,parabola)
hold on
plot(xj,hj)
end

채택된 답변

Voss
Voss 2022년 4월 11일
Looks like you might have x1, x2, ..., x10 as well. If not, you can modify this accordingly.
h_all = {h1 h2 h3 h4 h5 h6 h7 h8 h9 h10};
x_all = {x1 x2 x3 x4 x5 x6 x7 x8 x9 x10};
x=-0.21:0.01:0.21;
h=0.098;
L=0.447;
g=9.81;
for i=1:1:10
figure
parabola=h+omegah(i)^2/(2*g)*(x.^2-L^2/12);
plot(x,parabola)
hold on
plot(x_all{i},h_all{i});
end
  댓글 수: 2
Michael
Michael 2022년 4월 11일
Thanks!
Voss
Voss 2022년 4월 11일
You're welcome!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by