I am trying to plot multiple data sets on one one diagram. When I use the plot function, I am not getting any data plots.

4 views (last 30 days)
Jeffrey Lewis
Jeffrey Lewis on 26 Apr 2022
Commented: DGM on 27 Apr 2022
I am a novice to Matlab. My goal for this code is to calculate exit Mach numbers and total pressure ratios using a set of equations. The following code is what I generated based on my knowledge (I am sure there is a better way) but for some reason, I am not getting any data plots. Code:
clc
clear all
M1 = [1:0.1:2.5]; %%Free Stream Mach
a = [-2.5:0.5:2.5]; %%Angles of Attack
gamma = 1.4;
Beta1 = [5 8 12]; %%Design 1
Beta2 = [7 8 10];%%Design 2
Beta3 = [5 10 10];%%Design 3
Beta4 = [8.33 8.33 8.33];%%Design 4
Beta5 = [3 5 17];%%Design 5
%%normal shock relation
for i=1:length(M1)
M2 = sqrt((1+((gamma-1)./2)*(M1(i).^2))./((gamma.*(M1(i).^2))-((gamma-1)./2)))
p2p1 = (1+((2.*gamma)./(gamma+1))*((M1(i).^2)-1))
p02p2 = (1+((gamma-1)./2).*M2.^2).^(gamma./(gamma-1))
p1p01 = (1+((gamma-1)./2).*M1(i).^2).^-(gamma./(gamma-1))
p02p01 = (p2p1).*(p02p2).*(p1p01)
hold on
end
%%Oblique shock relation
for i=1:length(M1)
for j=1:length(Beta1)
theta1 = atand(2.*cotd(Beta1(j)).*((((M1(i).^2).*(sin(Beta1(j))).^2)-1)./((M1(i).^2).*(gamma+cos(2.*Beta1(j)))+2)))
Mn1 = M1(i).*sind(Beta1(j));
Mn2 = sqrt((Mn1.^2)+(2./(gamma-1))./(((2.*gamma)./(gamma-1)).*(Mn1.^2)-1));
M2 = Mn2./(sind(Beta1(j)-theta1));
p2p1 = (1+((2.*gamma)./(gamma+1)).*((Mn1.^2)-1))
p02p2 = (1+((gamma-1)./2).*Mn2.^2).^(gamma./(gamma-1))
p1p01 = (1+((gamma-1)./2).*Mn1.^2).^-(gamma./(gamma-1))
p02p01 = (p2p1).*(p02p2).*(p1p01)
hold on
end
for j=1:length(Beta2)
theta2 = atand(2.*cotd(Beta2(j)).*((((M1(i).^2).*(sin(Beta2(j))).^2)-1)./((M1(i).^2).*(gamma+cos(2.*Beta2(j)))+2)))
Mn1 = M1(i).*sind(Beta2(j));
Mn2 = sqrt((Mn1.^2)+(2./(gamma-1))./(((2.*gamma)./(gamma-1)).*(Mn1.^2)-1));
M2 = Mn2./(sind(Beta2(j)-theta2));
p2p1 = (1+((2.*gamma)./(gamma+1)).*((Mn1.^2)-1))
p02p2 = (1+((gamma-1)./2).*Mn2.^2).^(gamma./(gamma-1))
p1p01 = (1+((gamma-1)./2).*Mn1.^2).^-(gamma./(gamma-1))
p02p01 = (p2p1).*(p02p2).*(p1p01)
hold on
end
for j=1:length(Beta3)
theta3 = atand(2.*cotd(Beta3(j)).*((((M1(i).^2).*(sin(Beta3(j))).^2)-1)./((M1(i).^2).*(gamma+cos(2.*Beta3(j)))+2)))
Mn1 = M1(i).*sind(Beta3(j));
Mn2 = sqrt((Mn1.^2)+(2./(gamma-1))./(((2.*gamma)./(gamma-1)).*(Mn1.^2)-1));
M2 = Mn2./(sind(Beta3(j)-theta3));
p2p1 = (1+((2.*gamma)./(gamma+1)).*((Mn1.^2)-1))
p02p2 = (1+((gamma-1)./2).*Mn2.^2).^(gamma./(gamma-1))
p1p01 = (1+((gamma-1)./2).*Mn1.^2).^-(gamma./(gamma-1))
p02p01 = (p2p1).*(p02p2).*(p1p01)
hold on
end
for j=1:length(Beta4)
theta4 = atand(2.*cotd(Beta4(j)).*((((M1(i).^2).*(sin(Beta4(j))).^2)-1)./((M1(i).^2).*(gamma+cos(2.*Beta4(j)))+2)))
Mn1 = M1(i).*sind(Beta4(j));
Mn2 = sqrt((Mn1.^2)+(2./(gamma-1))./(((2.*gamma)./(gamma-1)).*(Mn1.^2)-1));
M2 = Mn2./(sind(Beta4(j)-theta4));
p2p1 = (1+((2.*gamma)./(gamma+1)).*((Mn1.^2)-1))
p02p2 = (1+((gamma-1)./2).*Mn2.^2).^(gamma./(gamma-1))
p1p01 = (1+((gamma-1)./2).*Mn1.^2).^-(gamma./(gamma-1))
p02p01 = (p2p1).*(p02p2).*(p1p01)
hold on
end
for j=1:length(Beta5)
theta5 = atand(2.*cotd(Beta5(j))*((((M1(i).^2).*(sin(Beta5(j))).^2)-1)./((M1(i).^2).*(gamma+cos(2.*Beta5(j)))+2)))
Mn1 = M1(i).*sind(Beta5(j));
Mn2 = sqrt((Mn1.^2)+(2./(gamma-1))./(((2.*gamma)./(gamma-1)).*(Mn1.^2)-1));
M2 = Mn2./(sind(Beta5(j)-theta5));
p2p1 = (1+((2.*gamma)./(gamma+1)).*((Mn1.^2)-1))
p02p2 = (1+((gamma-1)./2).*Mn2.^2).^(gamma./(gamma-1))
p1p01 = (1+((gamma-1)./2).*Mn1.^2).^-(gamma./(gamma-1))
p02p01 = (p2p1).*(p02p2).*(p1p01)
hold on
end
end
plot(M1,p02p01, 'LineWidth', 4);

Accepted Answer

DGM
DGM on 26 Apr 2022
p02p01 is a scalar, so there's not really anything to plot. I imagine that's supposed to be a vector, but you're just overwriting the same value in the loops. If that's the case, you'll have to decide which of the intermediate calculations are to be saved and then save them to a vector.
  4 Comments
DGM
DGM on 27 Apr 2022
Yes, you should be able to work the first plot into each of the later plots if you want. You might need to play with the line properties, etc. to make them distinguishable.
figure
subplot(5,1,1)
% plot p02p01 in a heavy black line
plot(M1,p02p01,'k','LineWidth',2); hold on
% plot others in a lighter weight line, picking colors
% from the axes 'colororder' property
plot(M1,allP(:,:,1),'LineWidth',1);
subplot(5,1,2)
% ... and so on

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!