フィルターのクリア

How can I use FIND to extract the indices of 1 elements in a 0/1 matrix?

2 ビュー (過去 30 日間)
Sherwin
Sherwin 2016 年 10 月 3 日
コメント済み: Sherwin 2016 年 10 月 3 日
I only have some 0/1 matrices and they are generated randomly. How can I define X like this: (please see Matrix image)
The first index of X shows it's in the r-th(r=1) row, the second index shows it's the n-th 1 in that section in that row, and the third index shows it's in the s-th section of that row, and the value of X=K means that it’s the K-th element of that whole row (counting elements from the beginning of that row up to that 1). Here r=1:4 n=1:5 s=1:2

採用された回答

michael
michael 2016 年 10 月 3 日
[row,col] = find(X) returns the row and column subscripts of each nonzero element in array X
PS: matlab indexes are starting from 1, not from 0
  3 件のコメント
michael
michael 2016 年 10 月 3 日
"X=K means that it’s the K-th element of that whole row" you already have K in the results.
for the r: you have it as output of find
for the s: if col > some number
for the n: sum(A(row,s:col))-1
Sherwin
Sherwin 2016 年 10 月 3 日
Thank you so much..

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

その他の回答 (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