Working with fileDatastore and loading its data

조회 수: 2 (최근 30일)
Anezka Koterova
Anezka Koterova 2020년 9월 19일
편집: Cris LaPierre 2020년 9월 26일
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에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by