Plot bunch of 2D data to 3D surface plot

I have problems with plotting my data:
From several simulations I have numerous vectors z_data_i and y_data_i
I would like to 3D plot them, since all of the z and y data vectors are produced at different states x_state_i.
So:
z_data_1 = f(x_state_1, y_data_1)
z_data_2 = f(x_state_2, y_data_2)
...
z_data_LastSimulation = f(x_state_LastSimulation, y_data_LastSimulation)
whereas x_state_ith_Simulation is fix for each simulation. So I basically have 2D plots (each at state x_state_ith_Simulation) that I would like to combine to a 3D surface plot.
I have tried with mesh/meshgrid/surf but nothing worked.
Thank you so much for the help!!

 Respuesta aceptada

Star Strider
Star Strider el 20 de Jul. de 2019
Editada: Star Strider el 20 de Jul. de 2019
I have no idea what your functions and data are, however plotting them is straightforward using the plot3 function.
Example —
x = linspace(0, 2*pi, 150);
fcn = @(x,s) sin(x*s);
s = 1:5:25; % ‘State’ Vector
for k = 1:numel(s)
z_data(k,:) = fcn(x,s(k));
end
figure
hold all
for k = 1:numel(s)
plot3(x,z_data(k,:),ones(size(x))*s(k)) % Stacked 2D Plots
end
hold off
grid on
view(-30,20)
figure
surf(x, s, z_data) % Surface Plot
grid on
xlabel('x')
ylabel('s')
Experiment with this idea with your data to get the result you want.
EDIT — Added comment documentation.

8 comentarios

Ann Gerber
Ann Gerber el 20 de Jul. de 2019
Thank you so much! Together with the surf() edit you have just added this is exactely what I was looking for!
Star Strider
Star Strider el 20 de Jul. de 2019
As always, my pleasure!
Ann Gerber
Ann Gerber el 20 de Jul. de 2019
I am sorry, but I realides that this anyway didn't solve my problem.
The thing is, that my data is not connected through a function.
I just have data vectors.
So i have for each simulation (each of which with a different setting x_i) a data vector y_data_i and z_data_i. For each simulation x_i is different and outputs a new y_data and z_data vector.
Thanks a lot!
Star Strider
Star Strider el 20 de Jul. de 2019
I only used the function to create the matrix. It is not required.
If your data vectors are all the same lengths, just concatenate them along the appropriate dimension to create a matrix. (If they are different lengths, you can use linspace with interp1 to stretch or compress them to be the same lengtths.) Then use surf or mesh to create the 3D plot.
Ann Gerber
Ann Gerber el 22 de Jul. de 2019
Thanks a lot, i figured it!
Star Strider
Star Strider el 22 de Jul. de 2019
As always, my pleasure!
TwoPhotons
TwoPhotons el 12 de Oct. de 2021
I have a very similar question to this but a couple steps further. I have a 3D array where each page is a 2D fluorescence spectrum at a particular excitation wavelength, essentailly a signal vs. wavelength. So X and Z axis are wavelength and Y is intensity.
I can plot these each using plot3, but is there a way to create a mesh inbetween lines in the Z axis to create a topographical representation of the data? Essentially can a surface be generated from gathered data rather than from an equation?
Attached is a picture from the Royal Society's discussion on 3D flourescence, that's the end goal.
Star Strider
Star Strider el 12 de Oct. de 2021
@CAMDEN JOHNSON — The image appears to be equivalent to a MATLAB surf plot.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 20 de Jul. de 2019

Comentada:

el 12 de Oct. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by