フィルターのクリア

Append nested cells in a loop

2 ビュー (過去 30 日間)
Daniel
Daniel 2020 年 7 月 8 日
回答済み: Daniel 2020 年 7 月 8 日
I am trying to store nested cells in a loop, but can't figure it out. I'm pretty sure this is almost trivial, but it's escaping me. See code below for further explanation.
for i = 1:length(ccp)
for j = 1:length(cct)
if isempty(tsrx{i,j})==0 % tsrx has many empty cells and I'm trying to collect the non-empty
% ones here. Since I'm only proceeding with non-empty ones, I'm losing the j counter.
% What I'd like is, for each i, a cell like this:
% {{first non-empty j},{second non-empty j}{third non-empty j}...}, so each tsrbetapairs{i}
% has nested cells for each valid result of the if loop
tsrbetapairs{i} = {tsrx{i,j};betax{i,j};i;j};
end
end
end
I've a tried a few things, but none worked. I either get a bunch of empty cells or for each tsrbetapairs{i} I only get that last non-empty j.
  2 件のコメント
KSSV
KSSV 2020 年 7 月 8 日
You want the indices which are empty ?
Daniel
Daniel 2020 年 7 月 8 日
No. I want the non-empty ones. I want this result, for example:
tsrbetapairs{1} = {{[tsrx{1,1};betax{1,1};1;1]},{[tsrx{1,3};betax{1,3};1;3]}}
where tsrx{1,2} was empty and so it was skipped. This could be different for every i.

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

採用された回答

Daniel
Daniel 2020 年 7 月 8 日
Figured it out. This works, though I'm open to other suggestions.
count = 1;
for i = 1:length(ccp)
for j = 1:length(cct)
if isempty(tsrx{i,j})==0
tsrbetapairs{i}{count} = [tsrx{i,j};betax{i,j};i;j];
count = count+1;
end
end
count = 1;
end

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by