There are ways to solve your problem based on HISTC or ACCUMARRAY. However, the simplest approach if you really have only two situations (unique 1 or unique -1) is probably the following:
Hi...Thanks a lot for replying....its able to find the correct value. And to solve my purpose I just have to add a line which was suggested by mahdi. Thanks a lot...:)
Sagar, you should take the time to understand his example. In particular, see whatc is, whatc==1 is, etc. Maybe read about logical indexing, and if you cannot use the latter and really need the position of unique element(s), read about FIND.
Thank you....but unique command returns the values that are present in the vector so here it is -1 0 1. But I am looking for the single value that is either 1 or -1 and then the indices of that particular value.
Thank you...I appreciate your help. But the above solution is confined to a particular A(i guess) and its returing the indicies of only -1 if the elements of A changes.
Actually I have large number of different vectors and in each either 1 or -1 is unique (either only 1 or -1 in a vector like A=[1,1,1,-1,0,0] (-1 is occuring once),B=[-1,-1,-1,1,0,0](1 is occuring once)) so for A i should have the indices of -1 for B indices of 1. so I am looking for a code which will determine the unique number in a vector and return its corresponding indices and only of that particular number...not like unique function.
Unfortunately its not working as in the attached image you can see that 1 is the unique and its index should be 7 but the code is showing for -1 instead that is 1 2 3. where A=[-1 -1 -1 0 0 0 1 0].
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
0 Comments
Sign in to comment.