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

3 views (last 30 days)
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

Accepted Answer

Voss
Voss on 11 Apr 2022
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

More Answers (0)

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!