Structure array data extraction and processing
조회 수: 1 (최근 30일)
이전 댓글 표시
CCSD structure array has two fields: 'xc1' & 'xc2'. 'xc1' has three fields-'c1','c2', & 'c3' whereas xc2 has two fields-'c1', and 'c2'.
As I run the structure inside 'for loop' to extract & process the data,'xc1' is also gets processed for three fields as well as 'xc2'.
It is confusing why 'xc2' is getting processed for three fields whereas it has only two fields(ref:- Variable: cumulat(1,2)). Please help.
clear
clc
close all
S = load('CCSD.mat')
F = fieldnames(S);
for n = 1:numel(F)
F1 = fieldnames(S.(F{n}));
F11{n} = F1;
for n1 = 1:numel(F1)
t = S.(F{n}).(F1{n1}).cc.t;
nn{n1} = [F1{n1}];
output{n1} = cumtrapz (t);
NF = @(p,q) max(output{n1}(t<=q)) - min(output{n1}(t>=p));
PArea{n1} = NF(5, 6)
end
cumulat{n} = [nn', PArea'];
end
댓글 수: 0
답변 (1개)
Chris Burschyk
2022년 6월 20일
In the first run of your n-loop it assignes nn 3 values. In the next run it assigns only 2 values but the 3rd value doesn't get overwritten or deleted and stays the same. You either have to clear nn or give it another index like
nn{n1,n} = F1{n1};
Maybe this code works for you:
clear
clc
close all
S = load('CCSD.mat');
F = fieldnames(S);
for n = 1:numel(F)
F1 = fieldnames(S.(F{n}));
F11{n} = F1;
for n1 = 1:numel(F1)
t = S.(F{n}).(F1{n1}).cc.t;
nn{n1,n} = F1{n1};
output{n1} = cumtrapz (t);
NF = @(p,q) max(output{n1}(t<=q)) - min(output{n1}(t>=p));
PArea{n1,n} = NF(5, 6);
end
cumulat{n} = [nn(:,n), PArea(:,n)];
end
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!