Problem in find function???

3 ビュー (過去 30 日間)
galaxy
galaxy 2020 年 1 月 30 日
コメント済み: galaxy 2020 年 1 月 30 日
Dear bros,
I want to find the index of spesific element in a matrix, but I think there is problem
A = [1 0 2 0; 0 3 0 4; 5 0 6 7; 0 8 0 9]
[col, row] = find(A);
A =
1 0 2 0
0 3 0 4
5 0 6 7
0 8 0 9
col =
1
3
2
4
1
3
2
3
4
row = ...
col value is wrong, right ??
I think
col =
1
3
2
4
1
3
4
2
4
Is it bug ??? Do any one can explain to me.
Thank you

回答 (1 件)

KSSV
KSSV 2020 年 1 月 30 日
[row,col] = find(A);
First you will get rows and then columns ..
Check:
idx = find(A) ;
[i,j] = ind2sub(size(A),idx) ;
[i j row col]
  1 件のコメント
galaxy
galaxy 2020 年 1 月 30 日
Thank you for your reply
I want to get the columns which contains non zero value only.
I find in each row, so it was OK.

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by