4d smooth plot with slices

3 Ansichten (letzte 30 Tage)
tandemuse
tandemuse am 20 Jan. 2021
Bearbeitet: tandemuse am 20 Jan. 2021
Hello I have a txt file (I have attached it as "Data.txt") with 4 columns, each representing a variable x,y,z,v. I plot this in the following manner:
load("Data.txt")
x = Data(:,1);
y = Data(:,2);
z = Data(:,3);
v = Data(:,4);
scatter3(x,y,z,40,v,'filled')
colorbar
However I would like it to be a smooth object on which I can also take vertical, horizontal or whatever slices.
  5 Kommentare
tandemuse
tandemuse am 20 Jan. 2021
Bearbeitet: tandemuse am 20 Jan. 2021
load ("Data.txt")
x = Data(:,1);
y = Data(:,2);
z = Data(:,3);
v = Data(:,4);
surf(x,y,z,v)
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
Or:
load ("Data.txt")
x = Data(1:10:end,1);
y = Data(1:10:end,2);
z = Data(1:10:end,3);
v = Data(:,4);
[x,y,z] = meshgrid(x,y,z);
surf(x,y,z,v)
Error using matlab.graphics.chart.primitive.Surface
Value must be a vector or 2D array of numeric type.
Error in surf (line 145)
hh = matlab.graphics.chart.primitive.Surface(allargs{:});
Adam Danz
Adam Danz am 20 Jan. 2021
Z must be a matrix. X and Y can be matricies the same size as Z or vectors that define the rows and columns of Z. V has several options but the easiest is probably a matrix the same size as Z.
Anyway, the slice function Bjorn mentioned may be better to accomplish you goal of taking slices of the object.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

tandemuse
tandemuse am 20 Jan. 2021
Bearbeitet: tandemuse am 20 Jan. 2021

Weitere Antworten (1)

Bjorn Gustavsson
Bjorn Gustavsson am 20 Jan. 2021
I suggest you use the slice function for that, this type of plots is what that function was designed for.
If your Data are not on a regular grid you will have to re-interpolate it to a regular x-y-z grid. You can do that using scatteredInterpolant, see the help and documentation for how to use that.
If your data is on a regular plaid grid you simply have to reshape the data into 3-D arrays. After that is done you can slice to your hearts desires:
slice(x3d,y3d,z3d,V,[1,2,exp(1),3,pi],[0,log(2),2^.5],1+sqrt(5)/2),shading flat
HTH
  1 Kommentar
tandemuse
tandemuse am 20 Jan. 2021
Bearbeitet: tandemuse am 20 Jan. 2021
I take every 10th sample because otherwise meshgrid doesn't work:
load ("Data.txt")
x = Data(1:10:end,1);
y = Data(1:10:end,2);
z = Data(1:10:end,3);
v = Data(1:10:end,4);
The following produces an error:
F = scatteredInterpolant(x,y,z,v);
[xq,yq,zq] = meshgrid(x,y,z);
vq = F(xq,yq,zq);
slice(xq,yq,zq,vq,[],[],0)
Error using griddedInterpolant
Sample points must be unique and sorted in ascending order.
Error in interp3 (line 144)
F = griddedInterpolant(X, Y, Z, V, method,extrap);
Error in slice (line 103)
vi = interp3(x,y,z,v,xi,yi,zi,method);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by