Find rows with maximum number and replace them with 1
古いコメントを表示
I have a matrix with n rows and 1 column. I would like to find row which have the maximum number. Then, replace 1 in these rows and replace 0 in other rows.
For instance: I have matrix A and I would like to produce matrix B.
A=
5
0
0
4
3
0
B=
0
1
1
0
0
1
採用された回答
その他の回答 (2 件)
Walter Roberson
2016 年 8 月 8 日
B = A == min(A);
4 件のコメント
Maryam Hamrahi
2016 年 8 月 8 日
編集済み: Maryam Hamrahi
2016 年 8 月 8 日
Walter Roberson
2016 年 8 月 8 日
In your first example you want a 1 where each original value was 0, which was the smallest value in the matrix. In the second example, you do not want a 1 where each original value was 0, even though 0 is the smallest value in the matrix. Your examples are inconsistent with each other.
Also your original version talked about maximum but you wanted the 1 where the minimum was, so your examples are not consistent with the description either.
Maryam Hamrahi
2016 年 8 月 8 日
編集済み: Maryam Hamrahi
2016 年 8 月 8 日
Maryam Hamrahi
2016 年 8 月 8 日
What you ask and the example you show are not consistent. To produce what you show:
B = A == 0
1 件のコメント
Maryam Hamrahi
2016 年 8 月 8 日
カテゴリ
ヘルプ センター および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!