Identify number of arrays within each row of a cell

1 回表示 (過去 30 日間)
Alberto Acri
Alberto Acri 2023 年 1 月 9 日
回答済み: Mathieu NOE 2023 年 1 月 9 日
Hi. I have the attached cell (.mat file).
The result I want to get is the number of matrices containing in each row of the cell. For example:
  • row 1 contains 1 matrix and therefore the result I want is "result = 1";
  • row 4 contains 2 matrices and therefore the result I want is "result = 2".
I sketched a for loop but I would not know how to continue:
load cell_A.mat
ROW = height(cell_A);
COLUMN = width(cell_A);
for row = 1:ROW
for column = 1:COLUMN
% .........
end
end

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 1 月 9 日
hello Alberto
only one for loop needed (row direction)
try this :
load cell_A.mat
[R,C] = size(cell_A);
for k = 1:R % row loop
%# find empty cells in k th row
emptyCells = find(cellfun(@isempty,cell_A(k,:)));
result(k) = C - numel(emptyCells);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by