Save numbers (present within a cell) into a single matrix

1 回表示 (過去 30 日間)
Alberto Acri
Alberto Acri 2023 年 1 月 10 日
コメント済み: Stephen23 2023 年 1 月 10 日
Hi! How can I save the numbers the numbers contained in this cell as a matrix?
Also, instead of blanks [] I should have zeros 0. Thank you!

採用された回答

Stephen23
Stephen23 2023 年 1 月 10 日
S = load('example.mat');
C = S.example
C = 4×4 cell array
{[10]} {[ 12]} {[ 86]} {0×0 double} {[91]} {[ 24]} {0×0 double} {0×0 double} {[ 4]} {0×0 double} {0×0 double} {0×0 double} {[31]} {[ 66]} {[ 49]} {0×0 double}
C(cellfun(@isempty,C)) = {0};
M = cell2mat(C)
M = 4×4
10 12 86 0 91 24 0 0 4 0 0 0 31 66 49 0
  2 件のコメント
Alberto Acri
Alberto Acri 2023 年 1 月 10 日
Thank you for your answer! Could you tell me how I can know the amount of positive numbers (excluding zeros) within the matrix (or cell)? In this case I have 9 numbers in total.
Stephen23
Stephen23 2023 年 1 月 10 日
Count all non-zeros:
nnz(M)
Count only positive values:
nnz(M>0)

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by