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!