# 3D Graphic from 40 files

조회 수: 1(최근 30일)
Frank Pernett 2020년 9월 4일
답변: Frank Pernett 2020년 9월 5일
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:
filePattern = fullfile("Dives.mat");
matFiles = dir(filePattern);
for k = 1:length(matFiles)
baseFileName = matFiles(k).name;
fullFileName = fullfile(baseFileName);
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
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Frank Pernett 2020년 9월 4일
Hi Geoff. X will be the data points of Depth. Y will be Depth and Z will be the cases. X and Y will have the same dimension but it will change as every table has different values. And Z will be 40 that is the number of files.
Thanks

댓글을 달려면 로그인하십시오.

### 채택된 답변

Cris LaPierre 2020년 9월 5일
편집: Cris LaPierre 2020년 9월 5일
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
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Cris LaPierre 2020년 9월 5일
You will have to adapt my code to fit your data. However, I find your code a little confusing. Perhaps you have tried to edit it to make it simpler? You also use the same loop counter variable (k) in your nested for loops.
Here's your code modified (my best guess).
% I don't understand how this part works
filePattern = fullfile("Dives.mat");
matFiles = dir(filePattern);
for k = 1:length(matFiles)
baseFileName = matFiles(k).name;
fullFileName = fullfile(baseFileName);
end
% Once all the data is loaded, you can plot it in age order
[sAge,idx]=sort(Age);
fn = fieldnames(matData);
for k=1:numel(fn)
y=matData.(fn{idx(k)}).Depthm;
x = 1:length(y);
plot3(x,y,z*ones(size(x)))
hold on
end
hold off

댓글을 달려면 로그인하십시오.

### 추가 답변(1개)

Frank Pernett 2020년 9월 5일
Thank you so much Cris.
This is the result of your code ( I need to simplify mine a lot). Just need to adjust the axex, but that is not so difficult!!.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Numeric Types in Help Center and File Exchange

R2020a

### Community Treasure Hunt

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

Start Hunting!