Hi,
I have a hard code pasted below: Can anyone help me reducing the amount of lines I have plotted by putting this into loop. I would like to plot nearly 10 curves on the same graph.
Q = 1
Q1 = 9
Q2 = 8
Q3 = 7
Q4 = 6
Q5 = 5
Q6 = 4
Q7 = 3
Q8 = 2
Q9 = 1
depth = Q^(2/3)/(3*(g)^(1/3))
depth1 = Q1^(2/3)/(3*(g)^(1/3))
depth2= Q2^(2/3)/(3*(g)^(1/3))
depth3 = Q3^(2/3)/(3*(g)^(1/3))
depth4 = Q4^(2/3)/(3*(g)^(1/3))
depth5 = Q5^(2/3)/(3*(g)^(1/3))
depth6 = Q6^(2/3)/(3*(g)^(1/3))
depth7 = Q7^(2/3)/(3*(g)^(1/3))
depth8 = Q8^(2/3)/(3*(g)^(1/3))
depth9 = Q9^(2/3)/(3*(g)^(1/3))
A = Wvaries.*depth
A1 = Wvaries.*depth1
A2 = Wvaries.*depth2
A3 = Wvaries.*depth3
A4 = Wvaries.*depth4
A5 = Wvaries.*depth5
A6 = Wvaries.*depth6
A7 = Wvaries.*depth7
A8 = Wvaries.*depth8
A9 = Wvaries.*depth9
V = Q ./ A
V1 = Q1 ./ A1
V2 = Q2 ./ A2
V3 = Q3 ./ A3
V4 = Q4 ./ A4
V5 = Q5 ./ A5
V6 = Q6 ./ A6
V7 = Q7 ./ A7
V8 = Q8 ./ A8
V9 = Q9 ./ A9
plot (Wvaries,V);
hold on
plot (Wvaries,V1);
hold on
plot (Wvaries,V2);
hold on
plot (Wvaries,V3);
hold on
plot (Wvaries,V4);
hold on
plot (Wvaries,V5);
hold on
plot (Wvaries,V6);
hold on
plot (Wvaries,V7);
hold on
plot (Wvaries,V8);
hold on
plot (Wvaries,V9);
hold on
grid on

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 13 日
編集済み: Ameer Hamza 2020 年 10 月 13 日

0 投票

I guess you are trying to do something like this
g = 1;
Wvaries = 1:10;
Q = [1 9 8 7 6 5 4 3 2 1];
depth = Q.^(2/3)./(3*(g).^(1/3));
A = Wvaries.*depth;
V = Q ./ A;
plot (Wvaries, V);

7 件のコメント

muhammad choudhry
muhammad choudhry 2020 年 10 月 13 日
Hi, I am getting this error!
Matrix dimensions must agree.
Error in matlabhelp (line 9)
A = Wvaries.*depth;
muhammad choudhry
muhammad choudhry 2020 年 10 月 13 日
So, what I am trying to do here is:
Calculating different depth level on different flowrate.right ? and then using that different depth levels calculating different areas then use them different areas with different flowrate I am calculating different velocities. Once I have them range of velocities I am plotting them V(y-axis) against the Wvaries = [0.50:0.01:1.5] on x-axis..... but I am struggling to plot this using a simple code.
Ameer Hamza
Ameer Hamza 2020 年 10 月 13 日
There is a plot between three variables: V, Wvaries, and Q. How do you want to plot it? A separate plot for each value of Q or a 3D surface plot?
muhammad choudhry
muhammad choudhry 2020 年 10 月 13 日
Hi,
Please run a file I attached you, you will get it what is happening here!
I will also ask you If you can help me put the text Inbetween the curves as well. Please see the attached picture as well.
Regards
MSC
Ameer Hamza
Ameer Hamza 2020 年 10 月 13 日
Following is equivalent to your code.
Fr = 1;
Wvaries = (0.50:0.01:1.5).';
g = 9.81;
Q = 0.1:-0.01:0.01;
depth = Q.^(2/3)/(1.03*(g)^(1/3));
A = Wvaries.*depth;
V = Q ./ A;
ax = axes();
hold on
grid on
plot(Wvaries, V);
x = 1.05;
yline(x,'Color','b','LineStyle','--','LineWidth',1.5)
hold off
Putting text over the line is more complicated. There is no direct function. This shows one method of how it can be done: https://www.mathworks.com/matlabcentral/answers/484490-plot-text-on-line-with-angle
muhammad choudhry
muhammad choudhry 2020 年 10 月 14 日
Thanks alot for your help!
Ameer Hamza
Ameer Hamza 2020 年 10 月 14 日
I am glad to be of help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by