Filter löschen
Filter löschen

Removal of empty cells in an array

1 Ansicht (letzte 30 Tage)
Josh
Josh am 22 Jun. 2022
Kommentiert: Josh am 22 Jun. 2022
The variable: cumulat(1,2) is returning an empty third row. How does one not get that empty row? 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,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

Akzeptierte Antwort

Karim
Karim am 22 Jun. 2022
this was due to the indexing, you were putting the temporary data into "nn{n1,n} = F1{n1}", thus at the second run of "n" a new column would be added to "nn" and it would result in the same number of rows as "n=1".
The solution is to allocate a new cell at each loop.
S = load('CCSD.mat');
F = fieldnames(S);
for n = 1:numel(F)
F1 = fieldnames(S.(F{n}));
F11{n} = F1;
% allocate the variables
nn = cell(numel(F1),1);
PArea = cell(numel(F1),1);
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
cumulat
cumulat = 1×2 cell array
{3×2 cell} {2×2 cell}
cumulat{1,2}
ans = 2×2 cell array
{'c1'} {[5.5000]} {'c2'} {[5.5000]}
  1 Kommentar
Josh
Josh am 22 Jun. 2022
Your reasoning is correct. Thanks for the help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Stateflow finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by