how can i assign the same values in an array with 1?

1 次查看(过去 30 天)
I have an array as
A=[303
95
54
303
303]
I want to assign all same values as 1 and others as 0
A= [1
0
0
0
1
1]
  2 个评论
Stephen23
Stephen23 2016-2-6
编辑:Stephen23 2016-2-6
This is the same basic task as your last question:
Did you try any of the answers? What information do you expect that those answers did not give you?
suchismita
suchismita 2016-2-6
yes sir that was working but i wanted only 303 to get assigned as 1, i guess in your code itself if i am not rounding the data i will get more appropriate answer.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2016-2-6
newA = sum(bsxfun(@eq, A(:), A(:).')) > 1;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by