Creating Surface Plot from a Matrix with 3 Columns

How do you create a surface plot using a matrix with 3 columns in Matlab? The first column would be the x-values, the second column would be the y-values, and the third column would be the z-values for the surface plot.

3 件のコメント

KSSV
KSSV 2018 年 7 月 30 日
We can help on getting data. Attach your data. We need to know whether your data is structured or unstructured.
Sarah
Sarah 2018 年 7 月 30 日
I am generating data from a loop. Here is a simple example from the loop:
0.5000 0.5000 66.9052
0.5000 1.0000 57.3591
1.0000 0.5000 76.7805
1.0000 1.0000 66.9052
KSSV
KSSV 2018 年 7 月 30 日
More data is needed.

サインインしてコメントする。

 採用された回答

KSSV
KSSV 2018 年 7 月 30 日

6 投票

A = [0.5000 0.5000 66.9052
0.5000 1.0000 57.3591
1.0000 0.5000 76.7805
1.0000 1.0000 66.9052] ;
x = A(:,1) ; y = A(:,2) ; z = A(:,3) ;
%%structured
xi = unique(x) ; yi = unique(y) ;
[X,Y] = meshgrid(xi,yi) ;
Z = reshape(z,size(X)) ;
figure
surf(X,Y,Z)
%%unstructured
dt = delaunayTriangulation(x,y) ;
tri = dt.ConnectivityList ;
figure
trisurf(tri,x,y,z)

11 件のコメント

Sarah
Sarah 2018 年 7 月 30 日
Thank you. What is the "unstructured" section doing/for?
KSSV
KSSV 2018 年 7 月 30 日
YOu can plot in either of the ways. Thanks is accepting the answer..:)
Sarah
Sarah 2018 年 7 月 30 日
How do you know if you are "structured" vs "unstructured"?
KSSV
KSSV 2018 年 7 月 30 日
That's why I asked for complete data....:)
If X, Y have regaular arrangement it is structured or else unstructured.
Eric
Eric 2018 年 10 月 21 日
Wonderful...thank you soooo much for this!!! I was tearing my hair out. :)
Adithya Valavi
Adithya Valavi 2020 年 4 月 20 日
If you have n no matrix then can we draw multiple suface plot???
Felicity Currie
Felicity Currie 2020 年 6 月 8 日
thank you KSSV!
Timothy Turk
Timothy Turk 2020 年 9 月 15 日
KSSV - It works with your numbers, but it chokes on mine. I get an error on reshape.
Error using reshape
To RESHAPE the number of elements must not change.
Error in Iridium_Data (line 9)
Z = reshape(z,size(X)) ;
Rodrigues Bitha
Rodrigues Bitha 2021 年 3 月 29 日
@Timothy Turk I also encoutered the same issue. To solve this, I removed all the rows of my matrix that were repeated. You can do with the command:
B = unique(A,'rows');
Hope that will be helpful to you or anyone that will come after us.
Hans Kramer
Hans Kramer 2021 年 3 月 30 日
Thank you for the answer.
MOHAMED GHAZI
MOHAMED GHAZI 2022 年 4 月 3 日
KSSV how can I trisurf this matrix I used your email program it does not work.
P1=[1;0;1];
P2= [2; 3;2];
P3= [-3;1;2];
P4= [6;2;3];
MatrixP=[1 2 -3 6 ;0 3 1 2;1 2 2 3];
%%structured
[X,Y] = meshgrid(MatrixP) ;
B = unique(A,'rows');
figure
surf(X,Y,Z)
%%unstructured
dt = delaunayTriangulation(x,y) ;
tri = dt.ConnectivityList ;
figure
trisurf(tri,x,y,z)

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2021 年 10 月 9 日

2 投票

x = speed ; y = Torque ; z = bsfc ;
%%structured
xi = unique(x) ; yi = unique(y) ;
[X,Y] = meshgrid(xi,yi) ;
Z = reshape(z,size(X)) ;
figure
pcolor(X,Y,Z)
%% griddata
xi = linspace(min(x),max(x));
yi = linspace(min(y),max(y)) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y)
pcolor(X,Y,Z)

カテゴリ

タグ

質問済み:

2018 年 7 月 30 日

コメント済み:

2022 年 4 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by