简体   繁体   中英

Matlab coneplot meshgrid error MATLAB:griddedInterpolant:NdgridNotMeshgrid3DErrId / not plotting anythin

Basically I want to plot a 3D vector field using coneplot in Matlab. My script looks like this:

data=oommf2matlab('420x350x5-2_5-5.omf');
x=linspace(data.xmin,data.xmax,data.xnodes);
y=linspace(data.ymin,data.ymax,data.ynodes);
z=linspace(data.zmin,data.zmax,data.znodes);
[X,Y,Z]=meshgrid(y,x,z);
scale=4;
angle = data.datay ./ data.datax;
colors = angle;
figure;
coneplot(data.positionx,data.positiony,data.positionz,data.datax,data.datay,data.dataz,X,Y,Z,scale,colors);

oommf2matlab is a function for converting my data into matlab and returns a structure like this:

xmin: 0
ymin: 0
zmin: 0
xmax: 4.2400e-07
ymax: 3.5400e-07
zmax: 1.2500e-08
xnodes: 212
ynodes: 177
znodes: 5
datax: [212x177x5 double]
datay: [212x177x5 double]
dataz: [212x177x5 double]
positionx: [212x177x5 double]
positiony: [212x177x5 double]
positionz: [212x177x5 double]

Running this script gives me an error

Error using interp3 (line 146) Input grid is not a valid MESHGRID.

Error in coneplot (line 144) ui = interp3(x,y,z,u,cx,cy,cz,method);

Error in omf2cone (line 11) coneplot(data.positionx,data.positiony,data.positionz,data.datax,data.datay,data.dataz,X,Y,Z,scale,colors);

If traced the error via debugging to the MATLAB:griddedInterpolant:NdgridNotMeshgrid3DErrId error which looks like this:

identifier: 
'MATLAB:griddedInterpolant:NdgridNotMeshgrid3DErrId'

message: 
Data is in MESHGRID format, NDGRID format is required.
Convert your data as follows:
P = [2 1 3];
X = permute(X, P);
Y = permute(Y, P);
Z = permute(Z, P);
V = permute(V, P);
F = griddedInterpolant(X,Y,Z,V)
cause: {0x1 cell}
stack: [3x1 struct]

This is strange to me, because interp3 already does what the error suggests as a fix.

Also if I let coneplot generate the mesh itself via:

coneplot(data.datax,data.datay,data.dataz,X,Y,Z,scale,colors);

There is no error, however there is no plot created whatsoever, only the axis of the figure.

instead of using meshgrid use griddedInterpolant() instead so that your data is in the format identified in the error.

Also part of your error could be in this line [X,Y,Z]=meshgrid(y,x,z); where instead you want [X,Y,Z]=meshgrid(x,y,z); ? This could cause the syntax error you are describing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM