Delete Cells in Cell array in two loops....

2 ビュー (過去 30 日間)
Ibrahs
Ibrahs 2022 年 1 月 31 日
コメント済み: Rik 2022 年 2 月 1 日
Hi everyone,
I have the following code and want to delete the empty cells in the results:
tt1 = find(year(Time) == 2015 & month(Time) == 10);
tt2 = find(year(Time) == 2010 & month(Time) == 10);
tt3 = find(year(Time) == 2019 & month(Time) == 04);
JT = [ tt1; tt2; tt3 ];
H= [ 4, 8];
for h = H
for jt = JT'
PdfDat{h,jt+h}=strcat('T',num2str(year(Time(jt+h))), 'Q', num2str(ceil(month(Time(jt+h)) / 3)));
Pdfd{h,jt+h}=ResMatch_LU.PST(jt+h, :);
end
end
The results are the following in which I want to delete the [ ] such that the array will be presented in fucntion of 'h' and 'jt+h' :
I want also to delete [ ] in the cell "1x401 double" here in coulumns 52 and 56;
Could you please help me to do those changes? My Matlab version is R2015a.
Many thanks!

回答 (1 件)

Ankit
Ankit 2022 年 1 月 31 日
You can use cellfun: Apply a function to each cell of a cell array
'isempty' -- true for cells containing an empty array, false otherwise
PdfDat_new = PdfDat(~cellfun('isempty',PdfDat));
Pdfd_new = Pdfd(~cellfun('isempty',Pdfd));
  8 件のコメント
Ankit
Ankit 2022 年 2 月 1 日
why dont you use the method mentioned by rik? here with limited info and without having your relevant file it is not easy to reproduce the same problem
Rik
Rik 2022 年 2 月 1 日
It would probably help if you replace this loop:
for h=H
with this loop:
for n_H=1:numel(H)
h=H(n);
...
PdfDat_new{n_H}=...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by