Select only the matrices within the cell

1 回表示 (過去 30 日間)
Alberto Acri
Alberto Acri 2023 年 1 月 13 日
回答済み: Jan 2023 年 1 月 13 日
Hi. A simple method to select only the matrices within the cell?
I am trying to do something like this with this code but it doesn't save the matrices as the for loop progresses:
cell_new = {};
for ii = 1:8
matrix = cell{1, ii};
if isempty(matrix)
matrix_ex = cell{1, ii + 2};
else
matrix_ex = matrix;
end
end
cell_new = [cell_new; {matrix_ex}];

採用された回答

Image Analyst
Image Analyst 2023 年 1 月 13 日
Why not try it this way:
cell_new = {}; % Empty cell.
for k = 1: numel(originalCell)
matrix = originalCell{k};
if ~isempty(matrix)
cell_new = [cell_new; {matrix_ex}];
end
end

その他の回答 (2 件)

the cyclist
the cyclist 2023 年 1 月 13 日
Does this do what you want?
% Make up some input data, with one cell remaining empty
A = cell(3,1);
A{1} = rand(2,5);
A{3} = rand(7,11);
% Find the empty cells
indexToEmpty = cellfun(@isempty,A);
% Get only the non-empty cells;
B = A(~indexToEmpty)
B = 2×1 cell array
{2×5 double} {7×11 double}

Jan
Jan 2023 年 1 月 13 日
C = {rand(2), [], rand(3), [], [], rand(4)};
newC = C(~cellfun('isempty', C))
newC = 1×3 cell array
{2×2 double} {3×3 double} {4×4 double}

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by