90 views (last 30 days)

Show older comments

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?

Deepak Meena
on 21 Jan 2021

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

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

Start Hunting!