Effacer les filtres
Effacer les filtres

Removal of empty cells in an array

1 vue (au cours des 30 derniers jours)
Josh
Josh le 22 Juin 2022
Commenté : Josh le 22 Juin 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

Réponse acceptée

Karim
Karim le 22 Juin 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 commentaire
Josh
Josh le 22 Juin 2022
Your reasoning is correct. Thanks for the help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Stateflow dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by