Why my data is not plotting the graph using plot(Q,h)

조회 수: 1 (최근 30일)
muhammad choudhry
muhammad choudhry 2020년 10월 5일
댓글: KSSV 2020년 10월 5일
Hi,
I am not sure what is happening here? I am using the code below and all working fine but whenever it supposed to plot the graph it is not plotting the graph instead it is just printing all the values in command line section. So, I am using plot (Q,h) but whenever, i used scatter (Q,h) it put the points on the graph but for data representations I will need to plot the curves rather then scatter points.
I even used this code to join the scatter points but no result.
Code 2:
scatter(Q,h,'.','LineWidth',1);
line(Q,h,'Color','k','LineStyle','-','LineWidth',5)
hold on
Code1:
for Q = [0:1:100];
if h < h1
v_2 = ((Q/1000) / Area_Outlet1)
h = ((1 / (rho * g)) * (Patm2 - Patm1 + 0.5 * rho * (v_2^2 - v_1^2)) + h_f)*1000
else
v_2a = ((Q/1000) / Area_Outlet2)
h = h1 + ((1 / (rho * g)) * (Patm2 - Patm1 + 0.5 * rho * (v_2a^2 - v_1^2)) + h_f)*1000
end
plot (Q,h)
end
Any Help?

채택된 답변

KSSV
KSSV 2020년 10월 5일
편집: KSSV 2020년 10월 5일
q = [0:1:100];
h = zeros(size(q)) ;
for Q = 1:length(q)
if val < h1 % < --- think of this line
v_2 = ((Q/1000) / Area_Outlet1)
h(Q) = ((1 / (rho * g)) * (Patm2 - Patm1 + 0.5 * rho * (v_2^2 - v_1^2)) + h_f)*1000
else
v_2a = ((Q/1000) / Area_Outlet2)
h(Q) = h1 + ((1 / (rho * g)) * (Patm2 - Patm1 + 0.5 * rho * (v_2a^2 - v_1^2)) + h_f)*1000
end
end
plot (q,h)
  댓글 수: 8
muhammad choudhry
muhammad choudhry 2020년 10월 5일
Thanks alot that's work. But can you explain this code to me how is it different from the code I had initially, and what sort of changes you made? so, i do not run into problem in future.
I will be very thankful to you.
KSSV
KSSV 2020년 10월 5일
You want to save the output into a array h. So you have to update the value of h in the loop. The updated values of h should be comapred in the if else. You can see the code and relaize yourself where changes are made.
Thanks is accepting/ voting the answer. :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by