MATLAB: The data is not plotting the graph using plot(Q,h)

arraysdoublefor loopgraphif statementplotplottingscatter

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?

Best Answer

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)