Plotting a surface from a two-dimensional matrix

조회 수: 43 (최근 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 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