How do I plot xy plots into one 3D plot?

8 次查看(过去 30 天)
Hello dear community!
I am trying to make a 3D plot from my data. Each dataset includes depth measurements and absorbance measurements, which I usually plot in 2D as x = depth and y = absorbance. I saved all datasets as equal-size matrices with depth in the first column and absorbance in the second. There are multiple datasets per year, which are more or less evenly spaced (40 datasets per year), so I would like to combine them all in one plot, preferably a surface plot. As an additional variable I thought I could just use a vector (0:1:40) to distribute my depth/absorbance values according to that.
All tutorials that I found include some functions for z, but I don't have any, so I am not sure how to manage this.
Your help is really appreciated, thanks!
Eva
  8 个评论
Johannes Fischer
Johannes Fischer 2020-7-1
Sry, my mistake, the instructions on how to assign X, Y and Z should work with scatter3, but not surf.
For surf, all matrices must be of the same size since you want to have depth and time represented in the x y plane, the matrix size (in your example) for X and Y would need to be 3x1001 (assuming that the data in the files is 1001x2. Thus Z must also be 3x1001.
In general, try to avoid enumerating your variable names. This makes looping over data much easier
filenames = {'01_24_2008_for_3D_analysis', ...
'02_05_2008_for_3D_analysis', ...
'02_19_2008_for_3D_analysis'};
for ii = 1:numel(filenames)
%data = readmatrix(filenames{ii});
data = [(1:5)+rand(1, 5); ii*ones(1, 5)+rand(1, 5)]';
depths(:, ii) = data(:, 1);
crypto(:, ii) = data(:, 2);
end
t = repmat(1:numel(filenames), [size(depths,1) 1]);
figure
surf(depths, t, crypto)
Eva R
Eva R 2020-7-3
Thanks so much Johannes, works like a charm!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by