MATLAB: 3D Graphic from 40 files

3d plotsMATLAB

Hi. I have 40 tables that contain dive profiles (Dives.mat). As the sampling rate is 1 second, every datapoint for depth (Dephtm) is 1 second.
Every table has different sizes going from 8000 to 18000 rows. I use the next script to plot all dive profiles at once:
load Dives.mat
filePattern = fullfile("Dives.mat");
matFiles = dir(filePattern);
for k = 1:length(matFiles)
baseFileName = matFiles(k).name;
fullFileName = fullfile(baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
matData(k) = load(fullFileName);
fn = fieldnames(matData);
for k=1:numel(fn)
plot(matData.(fn{k}).Depthm);
hold on
end
hold off
end
And this is the result:
I have a 40 x 1 array with the Age of every diver.
My first question is how I can modify my code to plot a 3D graph where Z are the lines.
And the second, how can I link the Age array into the code to have the 3D graph ordered also by age.
Thanks

Best Answer

Here's one way. Since we didn't have your data, I made my own. You will have to do some adapting to get it to work with your variable names, though.
Age = randi(40,[40,1])+16;
% Sort age, capturing original position
[sAge,idx]=sort(Age);
% create structure with 40 random data series with lengths 8000-18000
for d = 1:40
r = randi(10000,1)+8000;
dive(d).depth = rand([r,1])*d;
end
% Plot depth data is dive structure. X=index, Y=depth,Z=case
for z=1:length(dive)
% plot dives in age order using Age sort index info
y=dive(idx(z)).depth;
x = 1:length(y);
plot3(x,y,z*ones(size(x)))
hold on
end
hold off