Working with fileDatastore and loading its data

7 次查看(过去 30 天)
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

回答(1 个)

Cris LaPierre
Cris LaPierre 2020-9-26
编辑:Cris LaPierre 2020-9-26
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)
See this example on the documentation page for load.

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by