Plotting a surface from a two-dimensional matrix

74 ビュー (過去 30 日間)
Mattia Boldrini
Mattia Boldrini 2020 年 8 月 4 日
回答済み: Deepak Meena 2021 年 1 月 21 日
Good day, I have the following problem:
I've run a simulation that produces some signals depending on two variables. As my advisor told me, I made a python pipeline that saves the simulated signals on a file in a two-dimensional matrix, with the first two columns being the sweeps of the two variables in all the possible permutations. For example. assuming that the two variables have values [1 2 3] and [4 5 6], the first two columns would be:
[1 4]
[1 5]
[1 6]
[2 4]
[2 5]
[2 6]
[3 4]
[3 5]
[3 6]
Now i have to plot these signals on surfaces on a 3d plot. From what I know, to plot a surface one needs the "surf" command, that takes two vectos with dimensions N and M, plus a two-dimensional matrix with dimensions N x M. The only way that i can think of to obtain this in my case would be to build a new data matrix from scratch using a for cycle, to assign the values of the error signals to two-dimensional matrix, but it seems unefficient and lenghty. Am i missing something?
  2 件のコメント
KSSV
KSSV 2020 年 8 月 4 日
編集済み: KSSV 2020 年 8 月 4 日
x = [1 2 3] ;
y = [4 5 6] ;
[X,Y] = meshgrid(x,y) ;
Z = sqrt(X.^2+Y.^2) ;
surf(X,Y,Z)
Okay, you have x, y but what about Z?
Mattia Boldrini
Mattia Boldrini 2020 年 8 月 4 日
so i cna use my already mashed grid as [X,Y]? all the other columns of the table are each a Z, each file contains multiple surfaces that i have to plot.

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

回答 (1 件)

Deepak Meena
Deepak Meena 2021 年 1 月 21 日
Hi Mattia ,
Since we want to have permutation for the create the Surface plot , mex grid will of great use. It returns 2-D grid coordinates based on the coordinates contained in vectors x and y. X is a matrix where each row is a copy of x, and Y is a matrix where each column is a copy of y. The grid represented by the coordinates X and Y has length(y) rows and length(x) columns.
so for your example x = [1 2 3 ] & y = [4 5 6]
>> X
X =
1 2 3
1 2 3
1 2 3
>> Y
Y =
4 4 4
5 5 5
6 6 6
>>
so we run
F = X.*exp(-X.^2-Y.^2);
surf(X,Y,F)
It plots for all the possible pairs of x and y. Since you have already a Z value associated value with them , you can plot the surface plot
Thanks

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by