Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: finding a column that has X element in each row

$
0
0
"Nasser M. Abbasi" <nma@12000.org> wrote in message <k8cao7$ivk$1@speranza.aioe.org>...
> On 11/18/2012 8:29 PM, Jinsoo wrote:
> > Hi,
> >
> > I have a question regarding how to find a column that has X element in each row.
> > For example,
> > a=
> > [ 1 2 3 4 5
> > 2 1 4 3 5
> > 3 4 5 1 2]
> >
> > I would like to find a column that has element 2 in each row.
> > My goal is to turn out data (from the above example) [2 1 5] which means
> >[column 2, column 1, column 5]
> >
> > Is there any way to do this?
> >
>
> to find things in matrices, use the find() command:
>
> ------------------
> [~,J] = ind2sub(size(a),find(a==2))
> ------------------
>
> 1
> 2
> 5
>
> --Nasser
>
I appreciate Nasser. Your reply helped me a lot. I would like to get the result in order of the row. Your result says that there is 2 in column 1, 2, and 5 while I would like to get column 2, column 1, column 5 in order of row 1, row 2, and row3. Is there any way to do this?

Viewing all articles
Browse latest Browse all 19628

Trending Articles