Trimming the contours on my plot
이전 댓글 표시
No matter what I try, I cannot trim the data of my contour plots. The contours are only supposed to fit inside the regular plot
% AE4802
% Spring 2021
% Assignment 3
clear;
clc;
hold off
plot(0,0)
% Information given in problem statement
W = 35000; % Weight (lbs)
S = 700; % Wing area (ft^2)
CLmax = 1.3; % Maximum lift coefficient
e = 0.75; %oswald efficiency
s = 60;
AR = s^2/S;
h = 15000; % Altitude of 15000 ft
n_max = 3.5; % Limit load factor of 3.5 g's
Vne = 350; % Never Exceed Speed (kts)
g = 32.1741; % Acceleration due to gravity (ft/s^2)
% Problem 3
%----------
% Create an array of load factors
n = 0:0.01:n_max;
K = 1/(pi*e*AR);
% Retreive the density at 15000 ft
[~,~,rho,~,~] = atmosphere(h);
% Calculate velocities (ft/s)
% V = sqrt(vecn.*2.*W./(rho.*S.*CLmax));
% Convert to knots
% kts = V./1.68781;
% calculation for contours
%[Cl,pc] = meshgrid(linspace(0,1.3,351),linspace(21,50,351));
[V,n] = meshgrid(linspace(0,350,351),linspace(0,3.5,351));
V = sqrt(n.*2.*W./(rho.*S.*CLmax));
Cl = linspace(0,1.3,351);
pc = 50.*ones(size(V));
% Convert to knots
kts = V./1.68781;
% Cl = linspace(0,1.3,351);
h = 15000.*ones(size(V));
% pc = 50.*ones(size(Cl));
[temp,pres,rho,mu,a] = atmosphere(h);
M = V./a;
m = W/g;
[thrust, ~, ~] = jt8d(M,h,pc);
CD = dragpolar(Cl,M);
D = 0.5.*rho.*V.^2.*S.*CD;
accel = (thrust - D)./m;
Tmax = jt8d(M,h,50*ones(size(M)));
nstall = (1./2.*W)*rho.*V.^2.*S.*CLmax; % n stall
% Create the plot
% figure()
plot(kts, n,'b') % Creates the Stall Limit
hold on
grid on
plot([kts(end), Vne],[n_max, n_max],'b') % Creates the Structural Load Limit
plot([Vne, Vne],[0, n_max],'b') % Creates the Never Exceed Speed Limit
% Using "end" gives the last element of that array/matrix/etc
% So kts(end) gives the last entry of the array kts
% Set the size of the plot
ylim([0, 4])
xlim([0, 375])
% Add the details
set(gca, 'FontName', 'Times New Roman')
title('V-n Diagram', 'FontName', 'Times New Roman')
xlabel('Airspeed (kts)', 'FontName', 'Times New Roman')
ylabel('Load Factor - n', 'FontName', 'Times New Roman')
% Display the cornering speed
fprintf('The cornering speed is %4.2f knots \n', kts(end));
plot(kts(n==max(n)), max(n),'.r','MarkerSize',20)
text(kts(n==max(n)), max(n),' cornering speed 251.38 kts', 'FontName', 'Times New Roman', 'FontSize', 12, 'Color', 'r', 'VerticalAlignment', 'bottom');
% Calculate and display the corresponding level turn radius in feet
Turn_radius = V(end)^2/(g*sqrt(n_max^2-1));
fprintf('The corresponding level turn radius is %4.2f feet \n', Turn_radius);
% Calculate and display the corresponding turn rate in deg/min at the
% cornering speed
Turn_rate = rad2deg((g*sqrt(n_max^2-1))/V(end)).*60;
fprintf('The corresponding turn rate is %4.2f °/min \n', Turn_rate);
hold on
%plotting contours
Vmargin(V > Vne) = NaN;
nmargin(n>3.5) = NaN;
kts(V > Vne) = NaN;
n_max(V>350) = NaN;
% mask = V > 350;
% V(mask) = NaN;
% n_max(mask) = NaN;
Vmargin(V>350) = NaN;
accel(n>3.5) = NaN;
accel(nstall<n) = NaN;
kts(n<nstall) = NaN;
[c,h] = contour(V(:,351),n(:,1),accel,'LineColor','k');
clabel(c,h,'FontName', 'Times New Roman');
% Save the plot
% print(gcf,'Question_3.png','-dpng','-r400');
댓글 수: 6
DGM
2021년 4월 27일
I can't run your code, since I don't know what atmosphere() function you're using. If it's a user-defined function, you can attach it.
Caroline Kenemer
2021년 4월 27일
DGM
2021년 4월 28일
How about dragpolar()?
Caroline Kenemer
2021년 4월 28일
DGM
2021년 4월 28일
Well, this is a start:
%plotting contours
hiV = (V > 350)'; % <-- need to transpose, since V,n aren't orthogonal anymore
accel(n>3.5) = NaN;
accel(hiV) = NaN;
accel(nstall<n) = NaN; % <-- nstall is huge, so this condition is never met
[c,h] = contour(V(:,351),n(:,1),accel,'LineColor','k');
clabel(c,h,'FontName', 'Times New Roman');
You might want to figure out why nstall is so much larger than n, and whether that's expected.
Caroline Kenemer
2021년 4월 28일
답변 (1개)
DGM
2021년 4월 28일
I was expecting to be able to do:
accel(n>nspeed') = NaN;
but n=nspeed
>> max(n(:,1)-nstall',[],'all')
ans =
8.8818e-16
n is just a linear ramp.
There's a lot of replicated data here. I was confused as to what was going on for quite some time due to the scaling, but I got it.
hiV = (V>350)';
accel(n>3.5) = NaN;
accel(hiV) = NaN;
accel(V'<kts) = NaN;

댓글 수: 2
Caroline Kenemer
2021년 4월 28일
DGM
2021년 4월 28일
No prob. If it's a satisfactory answer, just hit accept so the post gets put in the right category.
카테고리
도움말 센터 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!