How can I create a 2D contour Plot from X,Y,Z table?
Mostrar comentarios más antiguos
I am trying to plot the 2D contour from the equation. I have tried my code. However, It does not work. I give my code below. Thank you so much!.
num=50;
Lpmax=700e-6;
Lpmin=20e-6;
Lr=2.77e-3;
Cr=2.5e-9;
f=1/(2*pi*sqrt(Lr*Cr*0.5));
w=2*pi*f;
T=1/f;
Tdead=T*0.011;
Lp_x11=linspace(Lpmin,Lpmax,num);
Vs=linspace(140,340,num);
Vo=180;
Re_x11=200;
theta=0;
for i=1:num
% solve the D
syms D11
X=solve(sin(D11*pi)/(2*(1-D11))-Vo/Vs(i));
D_ch=X;
%
theta_dch=(2*pi*Tdead)/T;
A2=(1./(Re_x11.*(pi.^2).*(1-D_ch))).*2.*w.*Lp_x11(i).*sin(pi.*D_ch).*sin(pi.*(1-D_ch));
Qlr1=(2.*Vs(i).*sin(pi.*D_ch)./(Re_x11.*pi.*(1-D_ch).*w)).*(sin(-pi.*D_ch-theta_dch)-sin(-pi.*D_ch));
Qlr2=(2.*Vs(i).*sin(pi.*D_ch)./(Re_x11.*pi.*(1-D_ch).*w)).*(sin(pi*D_ch-theta_dch)-sin(pi.*D_ch));
Qlp_S1=-(1./w).*(Vs(i).*theta_dch./(w.*Lp_x11(i))).*(A2./(1-D_ch)-pi.*D_ch+theta_dch./2);
Qlp_S2=(1./w).*(D_ch.*Vs(i).*theta_dch)./(w.*Lp_x11(i).*(1-D_ch)).*(A2./D_ch+pi.*(1-D_ch)-theta_dch./2);
Qs1(i)=Qlp_S1+Qlr1;
Qs2(i)=Qlr2+Qlp_S2;
end
xv = linspace(min(Lp_x11), max(Lp_x11), 1000);
zv = linspace (min (Vs), max (Vs), 1000);
[X,Z] = meshgrid(xv, zv);
P = griddata(Lp_x11, Vs, Qs1, X, Z);
figure
scatter3(x, z, p, '.')
grid on
figure
meshc (X, Z, P)
grid on
figure
contourf(X, Z, P)
grid on
Respuesta aceptada
Más respuestas (1)
num=50;
Lpmax=700e-6;
Lpmin=20e-6;
Lr=2.77e-3;
Cr=2.5e-9;
f=1/(2*pi*sqrt(Lr*Cr*0.5));
w=2*pi*f;
T=1/f;
Tdead=T*0.011;
Lp_x11=linspace(Lpmin,Lpmax,num);
Vs=linspace(140,340,num);
Vo=180;
Re_x11=200;
theta=0;
Qs1 = zeros(1,num);
Qs2 = zeros(1,num);
for i=1:num
% solve the D
syms D11
X=vpasolve(sin(D11*pi)/(2*(1-D11))-Vo/Vs(i));
D_ch=double(X);
%
theta_dch=(2*pi*Tdead)/T;
A2=(1./(Re_x11.*(pi.^2).*(1-D_ch))).*2.*w.*Lp_x11(i).*sin(pi.*D_ch).*sin(pi.*(1-D_ch));
Qlr1=(2.*Vs(i).*sin(pi.*D_ch)./(Re_x11.*pi.*(1-D_ch).*w)).*(sin(-pi.*D_ch-theta_dch)-sin(-pi.*D_ch));
Qlr2=(2.*Vs(i).*sin(pi.*D_ch)./(Re_x11.*pi.*(1-D_ch).*w)).*(sin(pi*D_ch-theta_dch)-sin(pi.*D_ch));
Qlp_S1=-(1./w).*(Vs(i).*theta_dch./(w.*Lp_x11(i))).*(A2./(1-D_ch)-pi.*D_ch+theta_dch./2);
Qlp_S2=(1./w).*(D_ch.*Vs(i).*theta_dch)./(w.*Lp_x11(i).*(1-D_ch)).*(A2./D_ch+pi.*(1-D_ch)-theta_dch./2);
Qs1(i)=Qlp_S1+Qlr1;
Qs2(i)=Qlr2+Qlp_S2;
end
nnz(~isfinite(Lp_x11)), nnz(~isfinite(Vs)), nnz(~isfinite(Qs1))
xv = linspace(min(Lp_x11), max(Lp_x11), 1000);
zv = linspace(min(Vs), max(Vs), 1000);
[X,Z] = ndgrid(xv, zv);
F = scatteredInterpolant(Lp_x11(:), Vs(:), Qs1(:), 'linear', 'linear');
P = F(X, Z);
scatter(X(:), Z(:), 10)
figure
scatter3(X(:), Z(:), P(:), '.')
grid on
figure
meshc(X, Z, P)
grid on
figure
contourf(X, Z, P, linspace(-3e-6,4e-6,8))
grid on
nnz(isnan(P))
surf(X, Z, P, 'edgecolor', 'none')
2 comentarios
Walter Roberson
el 18 de En. de 2021
Okay, so what is happening is that when you calculate Qs1, you index Lp_x11(i) and Vs(i) . Both of those were created by linspace() with the same number of points, so they are in relationship, Vs(i) = A*Lp_x11(i) + B for some constants A and B.
Therefore, Qs1 is only being calculated along a line, and when you go to interpolate that line into 3 space, you do not have any information to interpolate off-axes, so it all interpolates as nan.
Tin Truong Chanh
el 19 de En. de 2021
Categorías
Más información sobre Axis Labels en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!








