converting vector result into matrices for surf command

Hello,in a program there is feald on aplane shown bellow.
the field data was exports and i am trying to recreate this fiels in matlab.
I have a problem where the exported tablable is show in the attached file ,the resulthas a vector as a result.
in surf command i needthe IMAGEEy result be a matrix
its folding every 24 members.
how can i recreate the photo of the progrm thanks?
I tried the photo shown bellow and it gave me gibrish
rows=(with.zmm==48.394400000000000);
data=with(rows,:);
x=data.xmm(1:24);
y=data.ymm;
y2=y(1:24:240);
z=reshape(data.EyImVm,24,[]);
[yy,xx]=meshgrid(x,y2)
surf(xx',yy',z)

Answers (2)

filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200898/with.txt';
with = readtable(filename);
with.Properties.VariableNames = {'xmm', 'ymm', 'zmm', 'ExReVm', 'ExImVm', 'EyReVm', 'EyImVm', 'EzReVm', 'EzImVm'};
rows = ismembertol(with.zmm,48.394400000000000);
data = with(rows,:);
x = data.xmm(1:24);
y = data.ymm;
y2 = y(1:24:240);
z = reshape(data.EyImVm,24,[]);
[yy, xx] = meshgrid(x, y2);
surf(xx',yy',z)
xlabel('x'); ylabel('y'); zlabel('EyImVm');

1 Comment

Hello i ineed to plot the Z-X surface data at Y=-11.340800000000000
how can wec cut in this plane?
Thanks.

Sign in to comment.

I have no idea what you want to plot.
Use the first two column (that correspond to ‘x’ and ‘y’ respectively), the choose whatever other column you want, and use scatter3 to plot them. m There is no need to reshape them.
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200898/with.txt')
T1 = 10560×9 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 _______ _______ ______ ________ ________ _______ _______ _________ ________ -48.384 -11.341 10.996 0.90813 1.8604 -37.911 -79.726 -2.0314 -3.5672 -46.047 -11.341 10.996 0.61978 1.2805 -36.158 -76.018 -0.69598 -0.80282 -43.709 -11.341 10.996 0.39263 0.83229 -35.522 -74.668 0.27129 1.1548 -41.372 -11.341 10.996 0.83176 1.7557 -35.755 -75.141 0.99512 2.5929 -39.034 -11.341 10.996 0.13691 0.29173 -35.001 -73.53 2.5863 5.8309 -36.697 -11.341 10.996 -0.57036 -1.1999 -35.671 -74.939 1.8947 4.2114 -34.36 -11.341 10.996 -0.98216 -2.0772 -39.062 -82.094 -1.6248 -3.4085 -32.022 -11.341 10.996 -1.0985 -2.3401 -45.176 -94.994 -7.9721 -17.029 -29.685 -11.341 10.996 3.0031 6.3116 -48.701 -102.43 -9.4638 -20.382 -27.348 -11.341 10.996 2.4817 5.2283 -41.237 -86.694 -3.1886 -7.3027 -25.01 -11.341 10.996 1.1922 2.5145 -36.242 -76.16 1.4338 2.3349 -22.673 -11.341 10.996 0.22708 0.4812 -34.936 -73.407 2.2261 3.9499 -20.335 -11.341 10.996 -0.32721 -0.67962 -34.818 -73.17 1.827 3.1152 -17.998 -11.341 10.996 -0.41435 -0.88218 -34.896 -73.346 1.5551 2.6268 -15.661 -11.341 10.996 -0.51603 -1.11 -35.857 -75.404 0.60022 0.71022 -13.323 -11.341 10.996 -0.41121 -0.89323 -37.957 -79.868 -0.086691 -0.62588
x = T1{:,1};
y = T1{:,2};
z = T1{:,3};
Eyv = T1{:,6};
figure
scatter3(x, y, z, 10, z, 'filled')
grid on
colormap(turbo)
view(30,20)
figure
scatter3(x, y, Eyv, 10, Eyv, 'filled')
grid on
colormap(turbo)
view(30,20)
Experiment to get the desired result.
.

6 Comments

Hello i ineed to plot the Z-X surface data at Y=-11.340800000000000
how can wec cut in this plane?
Thanks.
I am having a problem understanding what you want to do.
Using only the first 24 elements of each vector (corresponding to y=-11.3408) I get these results —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200898/with.txt')
T1 = 10560×9 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 _______ _______ ______ ________ ________ _______ _______ _________ ________ -48.384 -11.341 10.996 0.90813 1.8604 -37.911 -79.726 -2.0314 -3.5672 -46.047 -11.341 10.996 0.61978 1.2805 -36.158 -76.018 -0.69598 -0.80282 -43.709 -11.341 10.996 0.39263 0.83229 -35.522 -74.668 0.27129 1.1548 -41.372 -11.341 10.996 0.83176 1.7557 -35.755 -75.141 0.99512 2.5929 -39.034 -11.341 10.996 0.13691 0.29173 -35.001 -73.53 2.5863 5.8309 -36.697 -11.341 10.996 -0.57036 -1.1999 -35.671 -74.939 1.8947 4.2114 -34.36 -11.341 10.996 -0.98216 -2.0772 -39.062 -82.094 -1.6248 -3.4085 -32.022 -11.341 10.996 -1.0985 -2.3401 -45.176 -94.994 -7.9721 -17.029 -29.685 -11.341 10.996 3.0031 6.3116 -48.701 -102.43 -9.4638 -20.382 -27.348 -11.341 10.996 2.4817 5.2283 -41.237 -86.694 -3.1886 -7.3027 -25.01 -11.341 10.996 1.1922 2.5145 -36.242 -76.16 1.4338 2.3349 -22.673 -11.341 10.996 0.22708 0.4812 -34.936 -73.407 2.2261 3.9499 -20.335 -11.341 10.996 -0.32721 -0.67962 -34.818 -73.17 1.827 3.1152 -17.998 -11.341 10.996 -0.41435 -0.88218 -34.896 -73.346 1.5551 2.6268 -15.661 -11.341 10.996 -0.51603 -1.11 -35.857 -75.404 0.60022 0.71022 -13.323 -11.341 10.996 -0.41121 -0.89323 -37.957 -79.868 -0.086691 -0.62588
x = T1{:,1};
y = T1{:,2};
z = T1{:,3};
Eyv = T1{:,6};
Uy = unique(y)
Uy = 10×1
-11.3408 -9.0034 -6.6660 -4.3286 -1.9912 0.3462 2.6836 5.0210 7.3584 9.6958
% Uym = buffer(Uy,10)
ixr = 1:24;
figure
scatter3(x(ixr), y(ixr), z(ixr), 15, z(ixr), 'filled')
grid on
colormap(turbo)
view(30,20)
figure
scatter3(x(ixr), y(ixr), Eyv(ixr), 15, Eyv(ixr), 'filled')
grid on
colormap(turbo)
view(30,20)
Creating a plane from it —
yv = linspace(min(y(ixr))-0.01, max(y(ixr))+0.01, 24).';
[X,Y] = ndgrid(x(ixr), yv);
% NaNs = nnz(isfinite(Eyv(ixr)))
Z = griddata(x(ixr), yv, Eyv(ixr), X, Y)
Z = 24×24
-37.9109 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN -36.1583 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN -35.5220 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN -35.7548 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN -35.0008 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN -35.6706 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN -39.0625 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN -45.1763 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN -48.7008 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN -41.2371 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
figure
surf(X, Y, Z)
grid on
I am not geting any decent results from this.
.
If you have a 3D cuboid of data (not 2D X and Y and corresponding 2D Z), then you can use slice to visualize along arbitrary planes.
This will not work for the 2D/2D/2D gridded case.
If you had non-gridded vectors of X Y Z where the X Y do not happen to all fall along one plane, then you could potentially griddata() or scatteredInterpolant() to create a 3D volume that you could then slice()
@Walter Roberson — I'm having a difficult time understanding what is desired here.
A line, maybe? Constant z and constant y over a source that is a grid of data would still leave open the possibility of a line graph, EyImVm vs x ?
Certainly! Although some sort of scatter plot is at the base of this. The surface — if one exists — evolves from that. I just don’t understand how to get there from the provided data.

Sign in to comment.

Asked:

on 20 Nov 2022

Commented:

on 22 Nov 2022

Community Treasure Hunt

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

Start Hunting!