question regarding ploting a table as a surface
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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');
0 Kommentare
Antworten (2)
Voss
am 20 Dez. 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')
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')
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.
0 Kommentare
Cris LaPierre
am 20 Dez. 2022
Bearbeitet: Cris LaPierre
am 20 Dez. 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 Kommentar
Cris LaPierre
am 20 Dez. 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).
Siehe auch
Kategorien
Mehr zu Orange finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!