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

조회 수: 8 (최근 30일)
Eva R
Eva R 2020년 6월 30일
댓글: Eva R 2020년 7월 3일
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