How to get a matrix with different row lengths?

25 ビュー (過去 30 日間)
Sohaib Bin Altaf
Sohaib Bin Altaf 2018 年 5 月 1 日
コメント済み: Ameer Hamza 2018 年 5 月 1 日
I have a two dimensional matrix "check" of zeros and ones. I need to check the ones in each row, take the indexes of ones and store in another matrix. the number of ones are different in each row so the resultant matrix will have different lengths. How do i store them in one matrix?
for i=1:length(NewAps_1)
I2(i,:)=find(check_Naps(i,:))
end
the I2 matrix is the resultant matrix.

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 1 日
You cannot do that in matrices, because matrix rows need to be equal length. For that, you will need cell array. You can do the following to make cell array
I2 = cell(1, length(NewAps_1));
for i=1:length(NewAps_1)
I2{i}=find(check_Naps(i,:));
end
  4 件のコメント
Sohaib Bin Altaf
Sohaib Bin Altaf 2018 年 5 月 1 日
Thanks a lot sir for your help. God bless you.
Ameer Hamza
Ameer Hamza 2018 年 5 月 1 日
You are welcome.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by