Index of matrix element in Matlab

Status
Not open for further replies.

tombraided

Newbie level 2
Joined
Jan 22, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
London
Activity points
1,295
Hi there...

I have a matrix as:

a = [1 3 2 6 8 9 6]

can anyone tell how I would be able to get the index of the element(s) for 6. Here the answer should be [4,7]. It should be in matlab.


Thanks in advance.


-JML
 

I don't understand how you came up with [4,7].

Anyways, there is command ind2sub for that. And to go backwards sub2ind.

Hope this helps
 

a = [1 3 2 6 8 9 6];

if you want to get the index of the element(s) for 6, you should type with the following command

find(a == 6)

Therefore, the answer is 4 and 7

ps. I use matlab version 7.6 (R2008a) with the above command.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…