I cannot extract data from syms surface plot: Struct contents reference from a non-struct array object
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Subhrangsu Sarkar
le 20 Jan 2022
Commenté : Star Strider
le 20 Jan 2022
Hi!,
When I am trying to extract (x,y,z) data from a surface plot generated by the following code:
syms q_par_pipi_2 q_perp_pipi_2 Chi_xx_pipi_2
qx_pipi_2=q_par_pipi_2./sqrt(2);
Gamma_q_par_pi0_1=(1/2)*(cos(q_par_pi0_1)+1);
omega_bq_par_pi0_1=2*J*sqrt((1-Gamma_q_par_pi0_1)*(1+Gamma_q_par_pi0_1+J_perp_1/(2*J)));
omega_aq_par_pi0_1=2*J*sqrt((1+Gamma_q_par_pi0_1)*(1-Gamma_q_par_pi0_1+J_perp_1/(2*J)));
A1=q_perp_pi0_1*d/2;
B1=J*(1-Gamma_q_par_pi0_1)/omega_bq_par_pi0_1;
C1=(J*(1-Gamma_q_par_pi0_1)+(1/2)*J_perp_1)/omega_aq_par_pi0_1;
Chi_xx_pi0_1=(cos(A1)^2)*B1+(sin(A1)^2)*C1;
fsurf(Chi_xx_pi0_1,[0 1 0 1],'DisplayName','(pi,0), J_perp = + 0.5J',...
'Parent',axes1,...
'FaceColor',[0.749019622802734 0.749019622802734 0]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
%%get data
XX = dataObjs.XData ;
YY = dataObjs.YData ;
ZZ = dataObjs.ZData ;
I am getting the following error: Struct contents reference from a non-struct array object.
The plot is fine, but cannot extract any data.
The second part works normally with surface plots generated from non-syms generated plots.
Can you please help me understand? Is there any other way?
0 commentaires
Réponse acceptée
Star Strider
le 20 Jan 2022
I can’t run the posted code because there are missing elements.
Neverhteless, everything necessary to extract the data and reconstruct it as a surf plot is available, although it takes a bit of effort to retrieve it and put it in a form that surf can use —
syms x y
f(x,y) = exp(-(x-5)^2/5) + exp(-(y-5)^2/5)
figure
hfp = fsurf(f, [0 10 -5 15]);
legend('Location','best')
% GetPlotHandleData = get(hfp)
Xv = hfp.XData;
Yv = hfp.YData;
Zv = hfp.ZData;
% Ax = gca;
% xt = Ax.XTick
% yt = Ax.YTick
% zt = Ax.ZTick
Xm = reshape(Xv(1:hfp.MeshDensity^2), hfp.MeshDensity, []); % Create Matrix From Vector
Ym = reshape(Yv(1:hfp.MeshDensity^2), hfp.MeshDensity, []); % Create Matrix From Vector
Zm = reshape(Zv(1:hfp.MeshDensity^2), hfp.MeshDensity, []); % Create Matrix From Vector
figure
surf(Xm, Ym, Zm)
I am not certain how general this is since I only tested it on this function with these limits. It should get you started with your data.
.
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Preprocessing Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!