필터 지우기
필터 지우기

read and store data from struct file during each iteration in the for loop

조회 수: 2 (최근 30일)
Hi,
I have a for loop as shown. During each iteration the will store entire output in the struct file named Measurements. (file attached here)
From this struct file file, I need to read and store only 'Centroid', 'Eccentricity', 'EquivDiameter' in the sepearte array.
for i = 1:1:1000
% some operation
Measurements = some operation
end

채택된 답변

Star Strider
Star Strider 2024년 5월 4일
I am not certain what result you want.
Try this —
% load('matlab')
% whos('-file', 'matlab')
%
% Measurements
fields = {'Centroid', 'Eccentricity', 'EquivDiameter'};
files = dir('*.mat');
NrFiles = numel(files);
for k = 1:NrFiles
LD = load(files(k).name);
MeasTable = struct2table(LD.Measurements);
VN = MeasTable.Properties.VariableNames;
ColNrs = find(ismember(VN,fields));
ForFile = MeasTable(:,ColNrs);
writetable(ForFile,sprintf('NewTable%04d.txt',k))
end
readtable('NewTable0001.txt')
ans = 8x4 table
Centroid_1 Centroid_2 Eccentricity EquivDiameter __________ __________ ____________ _____________ 268.6 397.8 0.76509 2.5231 333.8 643.5 0.33229 9.4407 339.86 403.57 0.54188 13.303 355.02 557.21 0.66171 34.761 355.85 445.2 0.47857 34.943 356.29 744.16 0.35417 35.396 353.46 806.41 0.25141 26.511 360.73 838.97 0.44367 28.702
If all the .mat files have the same internal structure, then ‘MeasTable’ also will, and some of the lines in the loop can be defined prior to it.
.
  댓글 수: 20

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by