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
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!