3D Graphic from 40 files
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 2
Geoff Hayes
2020년 9월 4일
Frank - please clarify My first question is how I can modify my code to plot a 3D graph where Z are the lines. Does this mean that you want the depth to be that value for the z-axes? What will be used for the other two dimensions?
채택된 답변
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
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).
load Dives.mat
% 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);
fprintf(1, 'Now reading %s\n', fullFileName);
matData(k) = load(fullFileName);
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!