question regarding ploting a table as a surface

2 views (last 30 days)
Hello, i have the following EM field shown bellow, i have extracted the field into a table attached as zipped txt and a printscreen shown bellow.
i have only one value for each (x,z) coordinate how do i recreate this plot in matlab?
Thanks.
data=readtable('export.txt');
data_vec=data(:,4);
d_y_arr=table2array(data_vec);
mat_data=reshape(d_y_arr,[230,230]);
z_vec=table2array(data(1:230,3));%taking the repetative 230 values of z vector
x_vec=table2array(data(1:230:end,1));%take every 230 member for vector of x
[xx,zz]=meshgrid(x_vec,z_vec);
h=surf(xx,zz,mat_data)
set(h,'linestyle','none');

Answers (2)

Voss
Voss on 20 Dec 2022
You can use the four-input syntax for surf (X,Y,Z,C), and set the Y to zeros.
unzip('export.zip')
data=readtable('export.txt')
data = 52900×9 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 ______ ____ _____ __________ _______ __________ __________ __________ __________ -13.45 0 -7.45 -0.0054221 1.0022 0.0001463 0.00027693 0.00032724 -0.0032107 -13.45 0 -7.35 0.015197 0.99913 0.0001455 0.0002827 0.00034654 -0.0032987 -13.45 0 -7.25 0.035816 0.99607 0.00014469 0.00028847 0.00036585 -0.0033867 -13.45 0 -7.15 0.056435 0.99302 0.00014388 0.00029424 0.00038515 -0.0034746 -13.45 0 -7.05 0.077055 0.98996 0.00014308 0.00030001 0.00040446 -0.0035626 -13.45 0 -6.95 0.097674 0.9869 0.00014227 0.00030577 0.00042376 -0.0036506 -13.45 0 -6.85 0.11829 0.98385 0.00014147 0.00031154 0.00044307 -0.0037386 -13.45 0 -6.75 0.13891 0.98079 0.00014066 0.00031731 0.00046237 -0.0038265 -13.45 0 -6.65 0.15953 0.97774 0.00013985 0.00032308 0.00048168 -0.0039145 -13.45 0 -6.55 0.18015 0.97468 0.00013905 0.00032885 0.00050098 -0.0040025 -13.45 0 -6.45 0.20077 0.97162 0.00013824 0.00033462 0.00052028 -0.0040904 -13.45 0 -6.35 0.22139 0.96857 0.00013744 0.00034038 0.00053959 -0.0041784 -13.45 0 -6.25 0.24201 0.96551 0.00013663 0.00034615 0.00055889 -0.0042664 -13.45 0 -6.15 0.26263 0.96245 0.00013582 0.00035192 0.0005782 -0.0043544 -13.45 0 -6.05 0.28325 0.9594 0.00013502 0.00035769 0.0005975 -0.0044423 -13.45 0 -5.95 0.30243 0.95169 0.00013413 0.00036394 0.0006249 -0.0045988
N = 230;
mat_data=reshape(data{:,4},[N,N]);
z_vec=data{1:N,3};%taking the repetative 230 values of z vector
x_vec=data{1:N:end,1};%take every 230 member for vector of x
[xx,zz]=meshgrid(x_vec,z_vec);
colormap(jet)
% h=surf(xx,zz,mat_data,'linestyle','none')
h=surf(xx,zeros(N),zz,mat_data,'linestyle','none')
h =
Surface with properties: EdgeColor: [0 0 0] LineStyle: 'none' FaceColor: 'flat' FaceLighting: 'flat' FaceAlpha: 1 XData: [230×230 double] YData: [230×230 double] ZData: [230×230 double] CData: [230×230 double] Show all properties
colorbar
% caxis([0 1]) % if you want the color-limits to be [0,1] as in the picture
box on
xlabel('x')
ylabel('y')
zlabel('z')
Note that you're using the 4th column of data (ExRe), but the 5th column (ExIm) is pointed to in the table screenshot.

Cris LaPierre
Cris LaPierre on 20 Dec 2022
Edited: Cris LaPierre on 20 Dec 2022
Depending how exactly you are trying to duplicate the image you shared, it looks like you don't want a surface. You want to use scatter3 or plot3. Another observation is that the markersizse appears to change with the value of V/m.
Not perfect, but here's some code that could get you started.
unzip('export.zip')
data=readtable('export.txt');
sz = rescale(abs(data.Var5),0.1,5);
scatter3(data.Var1,data.Var2,data.Var3,sz,abs(data.Var5),"filled")
colormap jet
c = colorbar;
c.Title.String = 'V/m';
c.Title.FontSize = 14;
c.Title.FontWeight = "bold";
axis off
axis equal
grid off
box on
  1 Comment
Cris LaPierre
Cris LaPierre on 20 Dec 2022
Another thing to note is that, in the shared image, the data displayed in the figure is a subset of the full dataset (I counted 31 rows of data, while the raw dataset has 230).

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!