How do I plot xy plots into one 3D plot?
Show older comments
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 Comments
KSSV
on 30 Jun 2020
If you have only (x,y) how you can plot into 3D?
Eva R
on 30 Jun 2020
bharath pro
on 30 Jun 2020
You could define z as a combination of the year and the nth dataset from that year. But the z axis wouldnt have any meaningful value as such.
Eva R
on 1 Jul 2020
Johannes Fischer
on 1 Jul 2020
For X use depth, for Y use your time vector (0:1:40) and for Z use absorption.
For the Y-vector, consider that each time value has to be repeated N times, if N is the number of points at that time
% e.g.
N = 3;
t = [1 1 1 2 2 2 3 3 3];
Eva R
on 1 Jul 2020
Johannes Fischer
on 1 Jul 2020
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
on 3 Jul 2020
Answers (0)
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!