Working with fileDatastore and loading its data
7 views (last 30 days)
Show older comments
Hi,
I have a large files in Current file which I need to work with. These files are named D2_boneName.mat and contains doubles in only one row.
I would like to load each file and find the minimal and maximal number from each and finally count the histogram.
My script is this and the error is "Unable to use a value of type 'struct' as an index. Error in vypocti_cetnosti (line 10) maxK(i) = max(kost);"
Can you help me, how to rewrite it to work correctly?
fds = fileDatastore('D2_*.mat','ReadFcn',@load);
i = 1;
min=0;
max=0;
while hasdata(fds)
[kost,info] = read(fds);
maxK(i) = max(kost);
minK(i) = min(kost);
i = i+1;
end
dilek = (max(maxK)-min(minK))/50;
deleni = min(minK):dilek:max(maxK);
i=1;
while hasdata(fds)
[T_A,info] = read(fds);
kost = T_A{:,:};
[cetnostiObjemu,krajeObjemu]=histcounts(kost,deleni);
cetnostiObjemu=cetnostiObjemu/size(kost,2);
[~,fname] = fileparts(info.Filename);
save(['cetnosti_' fname], 'cetnostiObsahu')
i = i+1;
end
0 Comments
Answers (1)
Cris LaPierre
on 26 Sep 2020
Edited: Cris LaPierre
on 26 Sep 2020
What is the name of the variable you are loading? That is a fieldname in the structure kost. You access it using dot notation:
max(kost.Var)
0 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!