3D Graphic from 40 files

1 回表示 (過去 30 日間)
Frank Pernett
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:
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
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?
Frank Pernett
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
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 件のコメント
Frank Pernett
Frank Pernett 2020 年 9 月 5 日
編集済み: Frank Pernett 2020 年 9 月 5 日
Thank you Cris for your answer. I was trying to use it, but as files are mainly tables I got an error while trying to use length on it.
This are the files:
whos
Name Size Bytes Class Attributes
AN18 15067x3 363032 table
AY54 14512x3 349712 table
Age 40x1 320 double
EH67 15334x3 369440 table
FF22 14469x3 348680 table
FK55 14597x3 351752 table
HA67 14430x3 347744 table
HK41 14536x3 350288 table
HK75 10099x3 243800 table
HM77 15467x3 372632 table
HN60 14068x3 339056 table
HT40 14859x3 358040 table
KH39 11239x3 271160 table
KI70 14379x3 346520 table
KK55 14705x3 354344 table
KM42 15400x3 371024 table
KM45 14450x3 348224 table
KN70 14870x3 358304 table
MN65 11497x3 277352 table
MS60 8059x3 194840 table
MT61 14272x3 343952 table
MY32 13741x3 331208 table
NK81 14588x3 351536 table
NR57 17550x3 422624 table
OK55 17930x3 431744 table
OM40 14532x3 350192 table
OS49 14474x3 348800 table
RO79 14918x3 359456 table
SK74 8930x3 215744 table
SS32 11283x3 272216 table
SY43 15263x3 367736 table
SY57 14632x3 352592 table
TM29 16478x3 396896 table
TN61 13890x3 334784 table
TY53 15053x3 362696 table
YH58 9859x3 238040 table
YH81 14391x3 346808 table
YI61 9860x3 238064 table
YM47 10790x3 260384 table
YO57 15407x3 371192 table
YS72 16171x3 389528 table
baseFileName 1x9 18 char
filePattern 1x1 166 string
fn 40x1 4480 cell
fullFileName 1x9 18 char
idx 40x1 320 double
k 1x1 8 double
matData 1x1 13408856 struct
matFiles 1x1 1217 struct
sAge 40x1 320 double
When I run the script to generate the graph with all files fn has the legend of every case:
And the last 2 numbers are the age, could it be easier to extract the data from this?
Beside if i use this:
for k=1:numel(fn)
plot(matData.(fn{k}).TimeS,matData.(fn{k}).Depthm);
hold on
x and y are correct
Thanks
PS: I attached the 2 matfiles
Cris LaPierre
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 件)

Frank Pernett
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!!.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by