필터 지우기
필터 지우기

How to vertically concatenate certain fields of a structure on each pass of a loop?

조회 수: 1 (최근 30일)
i have a series of functions i need to analyze .txt files and pull relevant data for example, with the output from 'analyzedata' being a structure. How can i concatenate the results from each file to the results from previous files?
i want final to be a struct with the fields below, with those fields populated with the values from each loop of 'analyze data'
fields={'duration','temperture','RPM'}
final=struct(fields)
for k=1:numel(files)
.....
[data]=pulldata(filename)
[results]=analyzedata(data)
end
  댓글 수: 2
dpb
dpb 2022년 6월 23일
A structure array or a structure containing arrays? Two different things...
I'd ask why the structure and not a table, though??? Would fit very nicely and be as easy or easier to address.
Nicholas Kavouris
Nicholas Kavouris 2022년 6월 23일
a table would work for the final results, but the results of my analysis function contain a few arrays which are best suited to a structure.
i do not understand why it is so difficult to concatenate results from one field into another structure

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

답변 (1개)

Matt J
Matt J 2022년 6월 23일
clear results
for k=numel(files):-1:1
.....
data=pulldata(filename);
results(k)=analyzedata(data);
end
for f=string(fieldnames(results)')
final.(f)=vertcat( results.(f) );
end

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by