Extract specific X & Y data from Contour curve

38 views (last 30 days)
Hello MATLAB experts,
I have this below contour plot. How can I get the X and Y coordinate data for the specific contour line 1. Either in an array or table format would do the job.
Thanks for looking at it. I have attached the script for the reference.

Accepted Answer

Star Strider
Star Strider on 25 Aug 2022
Try this —
%% Input Parameters for Earth
Ctheta = 5;
Cphi = 0.001;
phimax = deg2rad(58);
thetamax = deg2rad(45);
alpha = (pi/2)-thetamax;
H1 = hypergeom([2],[3/2,5/2],-thetamax^2);
H2 = hypergeom([2],[1/2,5/2],-thetamax^2);
g = 3.72;
rho = 0.0142;
ge = 9.81;
rhoe = 1.225;
r2 = 0.554;
r3 = 0.59;
Cl = 1.1;
Ct = Cl/sin(2*alpha);
Cd = Cl*tan(alpha);
%% Kolomenskiy Model for Earth Bee
R = 13.2*10^(-3);
c = 4.02*10^-3;
S = 2.*R.*c;
M = 175*10^-6;
mw = 0.2251*R^3;
W = M*g;
%% Kolomenskiy model for Mars Bee
nx = 75;
ny = 75;
Wm_var_out = [];
Klm_out = [];
Kpm_out = [];
Lavg_out =[];
AeroPower_out = [];
PosPinert_out = [];
Iyy_out = [];
N = linspace(1,6,nx);
f = linspace(155,1,ny);
for i = 1:nx
R1 = N(i).*R;
c1 = 0.273.*R1;
mw_var = 0.2251.*R1^3;
Mm_var = M+mw_var;
Wm_var = Mm_var.*g;
Wm_var_out=[Wm_var_out Wm_var];
for j=1:ny
%Average Lift
Klm = rho.*f(j).*(R1.^(2) *r2^(2)).*(2.*R1.*c1).*Ct;
Klm_out = [Klm_out Klm];
Lavg1 = Klm.*sin(2*alpha);
Lavg2 = ((Cphi/(asin(Cphi)))^(2) * (2*pi^(2).*f(j).*phimax^(2))./(1+sqrt(1-Cphi^(2))));
Lavg = Lavg1.*Lavg2;
Lavg_out = [Lavg_out Lavg];
%Average Aerodynamic Power
Kpm = rho.*f(j).*(R1.^(3) *r2^(3)).*(2.*R1.*c1).*(2*Ct);
Kpm_out = [Kpm_out Klm];
% Variation of Flapping Angle
T = 1./f(j);
t =(0:0.00001:T/2);
phi_t = (phimax/asin(Cphi)).*(asin(Cphi.*cos(2*pi.*f(j).*t)));
% Flapping Velocity
phidot_t = (phimax/asin(Cphi)).*((-2*pi.*f(j).*Cphi.*sin(2*pi.*f(j).*t))./sqrt(1-(Cphi^2.*(cos(2*pi.*f(j).*t)).^2)));
% Flapping Acceleration
phi2dot_t = ((4*pi^2 .*f(j).^2 *Cphi *phimax)./asin(Cphi)).*((((Cphi^2.*cos(2*pi.*f(j).*t).*sin(2*pi.*f(j).*t).^2)./(1-(Cphi^2.*cos(2*pi.*f(j).*t).^2)).^(3/2))-(cos(2*pi.*f(j).*t)./sqrt(1-(Cphi^2.*cos(2*pi.*f(j).*t).^2)))));
% Pitching Angle Time variation
theta_t = (thetamax/tanh(Ctheta)).*tanh(Ctheta.*sin(2*pi.*f(j).*t));
% Average Integral Aerodynamic Power
alpha_t = (pi/2)-theta_t;
Kpm = rho.*f(j).*(R1.^3 * r3^3).*(2.*R1.*c1)*(2*Ct);
Pa = phidot_t.^3.*(sin(alpha_t)).^2;
AeroPower = Kpm.*trapz(t,abs(Pa));
AeroPower_out = [AeroPower_out AeroPower];
Pa_I = Kpm.*abs(Pa);
% Inertial Power
Iyy = 0.0426.*R1.^5;
Iyy_out = [Iyy_out Iyy];
Pinert = phidot_t.*Iyy.*phi2dot_t;
B = find(Pinert>=0);
PosPinert = trapz(t(B),Pinert(B))/(T/4);
PosPinert_out = [PosPinert_out PosPinert];
end
end
Ptotal = AeroPower_out+PosPinert_out;
A = reshape(Lavg_out,ny,nx);
C = reshape(Ptotal,ny,nx);
SpecificLift = A./Wm_var_out;
figure
contourf(N,f,SpecificLift,'ShowText','on')
hold on
[M,C] = contourf(N,f,SpecificLift,[1 2 4 6 8 10 12 14 16 18 20],'ShowText','on');
colormap jet
colorbar
title('SF vs Freq vs Specific Lift')
xlabel('Scaling Factor')
ylabel('Frequency')
Levels = C.LevelList
Levels = 1×11
1 2 4 6 8 10 12 14 16 18 20
for k = 1:numel(Levels)
idx = find(M(1,:) == Levels(k));
ValidV = rem(M(2,idx),1) == 0;
StartIdx{k,:} = idx(ValidV);
VLen{k,:} = M(2,StartIdx{k});
end
figure
for k1 = 1:numel(Levels)
% k1 = 4; % Index For Levels 'k1'
hold on
for k2 = 1:numel(StartIdx{k1})
idxv = StartIdx{k1}(k2)+1 : StartIdx{k1}(k2)+VLen{k1}(k2); % Index For Contour 'k1'
xv = M(1,idxv);
yv = M(2,idxv);
plot(xv, yv)
end
end
hold off
hl = legend(compose('%2d',Levels), 'Location','best', 'NumColumns',2);
title(hl, 'Specific Lift')
xlabel('M(1,:)')
ylabel('M(2,:)')
% title(sprintf('Contour Level %.1f', Levels(k1)))
% axis('equal')
.
  2 Comments
Chinmayraj Doddarajappa
Chinmayraj Doddarajappa on 25 Aug 2022
Thank you,
Your code is working.
Can you please brief me what the code is doing to get the X and Y coordinated.
Star Strider
Star Strider on 25 Aug 2022
As always, my pleasure!
The ‘xv’ and ‘yv’ values plot the curves for the ‘x’.and ‘y’ values respectively. Subscript them as:
xv{k1,k2} = M(1,idxv);
yv{k1,k2} = M(2,idxv);
where ‘k1’ are the indices of the levels (not the levels themselves), and ‘k2’ are the components of the contours (since in some contour plots, there may be several disconnected contours). For this contour plot, there should be only one (x,y) pair for each contour, so you can customise my code using only ‘k1’ for your contour plot.

Sign in to comment.

More Answers (1)

Matt J
Matt J on 25 Aug 2022
  5 Comments
Matt J
Matt J on 25 Aug 2022
Yes, that was what the link was for - the link you said you already downloaded from and tried.

Sign in to comment.

Categories

Find more on Contour Plots in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!