3D Graphic from 40 files
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Frank Pernett
le 4 Sep 2020
Réponse apportée : Frank Pernett
le 5 Sep 2020
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 commentaires
Geoff Hayes
le 4 Sep 2020
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?
Réponse acceptée
Cris LaPierre
le 5 Sep 2020
Modifié(e) : Cris LaPierre
le 5 Sep 2020
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 commentaires
Cris LaPierre
le 5 Sep 2020
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
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!