Plotting a surface from a two-dimensional matrix

43 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by