loading multiple groundtruth .mat files

Hi and good day to all,
I have 8 ground truth labelled .mat files from videos done by the matlab labeller.
I am trying to load such and I am uncertain of the next move.
Can a profession assist me please?
I have gotten this far with google, here's my code!
Thank you in advance!!
filenames = {'Beat1GTruth.mat','Beat2GTruth.mat','Fight1GTruth.mat','Fight2GTruth.mat','Shoot1GTruth.mat'...
,'Shoot2GTruth.mat','Stab1GTruth.mat','Stab2GTruth.mat'};
for kk = 1:numel(filenames)
load(filenames{kk})
end

回答(1 个)

Always load into an output variable (which is a scalar structure), e.g.:
F = {'Beat1GTruth.mat', 'Beat2GTruth.mat', 'Fight1GTruth.mat', 'Fight2GTruth.mat', 'Shoot1GTruth.mat', 'Shoot2GTruth.mat', 'Stab1GTruth.mat', 'Stab2GTruth.mat'};
N = numel(F);
C = cell(1,N);
for kk = 1:N
S = load(F{kk}); % load into a structure
% you can do anything with the structure contents, e.g.:
C{kk} = S.somefield; % !!! use an appropriate fieldname !!!
end
See also:

8 个评论

Hi Stephen Cobeldick and good morning to ya!
What is this piece of code can you describe it and thank you in advance for responding to me so swiftly
S.somefield?!!!???
C{kk} = S.somefield; % !!! use an appropriate fieldname !!!
I tried understanding the links you sent and I am not getting it! can you help me to understand please?
I am trying to have as my output file one variable as a table so I can proceed.
I am stuck at this level for some time just trying to figure out how to load all of these mat files at once and then proceed. please help!
Hi Stephen Cobeldick and thank you once more for responding!
I tired this code below which is the correct field name and it is still throwing an error!!! Please assist me!
thank you in advance!
C{kk} = S.BeatGTruth; % !!! use an appropriate fieldname !!!
%%% ERROR
Unfortunately each .mat file contain a differently-named variable. In future I strongly recommend that each .mat file should contain exactly the same variable names, this makes processing them in a loop easier and more robust.
Here is a work-around for your example files:
F = {'Beat1GTruth.mat', 'Beat2GTruth.mat', 'Fight1GTruth.mat', 'Fight2GTruth.mat', 'Shoot1GTruth.mat', 'Shoot2GTruth.mat', 'Stab1GTruth.mat', 'Stab2GTruth.mat'};
N = numel(F);
C = cell(1,N);
for kk = 1:N
S = load(F{kk}); % load into a structure
C(kk) = struct2cell(S); % !!! assumes only ONE field per structure !!!
end
T = [C{:}]; % optional but recommended: concatenate into one non-scalar structure
You can access the data in the non-scalar structure T using indexing and fieldnames:
For example, the MCOS data for the first file:
>> T(1).MCOS
ans =
3707764736
2
1
1
1
5
Hi Stephen Cobeldick and thank you for the advice I am grateful loads,
I am not sure how to do that but with trial research and my will I may get there, but i will welcome you teachings if you can demonstrate such with a link please!
In reference to your guidance,
Ok now this had no error running the operations.
I am seeing the S 1x1 struct variable in the workspace but there is only one field Stab2GTruth!!
Shouldn't I see the rest of the data file/field names from the other ,mat files loaded from the variable (F)!!???!!?? instead it is showing 8field with 1x1 groundTruth?!!!?!!
You do not appear to be running the complete code from my last comment.
Pease run the complete code that I gave, including the last line:
T = [C{:}];
T will then be a 1xN structure with two fields, it contains all of the data from all of your files.
I did see it and I ran it just as is!! that is what is confusing me!
I got to the step of training the cnn objectdetector but it came back with an error about the groundtruths not being in the right format!!
I am learning and it is fun! but not so much fun when I am stuck and not knowing nor understanding the full processes to move forward!
Please help!
and thank you in advance pal!

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Deep Learning Toolbox 的更多信息

提问:

2020-4-13

编辑:

2020-4-14

Community Treasure Hunt

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

Start Hunting!

Translated by