MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi
Learn moreOpportunities for recent engineering grads.
Apply TodayMATLAB Central > MATLAB Newsreader > find the column index of the first occurance of a ... 

Subject: find the column index of the first occurance of a value in each row From: metaug Date: 19 Aug, 2010 16:01:28 Message: 1 of 18 
I have a matrix A where 
Subject: find the column index of the first occurance of a value in each row From: Sean Date: 19 Aug, 2010 16:46:48 Message: 2 of 18 
metaug <hxhu76@gmail.com> wrote in message <1339137264.30660.1282233718285.JavaMail.root@gallium.mathforum.org>... 
Subject: find the column index of the first occurance of a value in each row From: Matt Fig Date: 19 Aug, 2010 17:01:17 Message: 3 of 18 
For a binary matrix, as shown in your example: 
Subject: find the column index of the first occurance of a value in each row From: Sean Date: 19 Aug, 2010 17:26:31 Message: 4 of 18 
"Matt Fig" <spamanon@yahoo.com> wrote in message <i4jo0s$6sb$1@fred.mathworks.com>... 
Subject: find the column index of the first occurance of a value in each row From: Matt Fig Date: 19 Aug, 2010 17:35:22 Message: 5 of 18 
"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i4jpg7$c7t$1@fred.mathworks.com>... 
Subject: find the column index of the first occurance of a value in each row From: Matt Fig Date: 19 Aug, 2010 17:51:10 Message: 6 of 18 
I am using 2007b, on XP 64. I am surprised to find that the niave FOR loop is WAY faster than either of our solutions. Sean, what are you using, and is this still true? 
Subject: find the column index of the first occurance of a value in each row From: Bruno Luong Date: 19 Aug, 2010 17:59:24 Message: 7 of 18 
metaug <hxhu76@gmail.com> wrote in message <1339137264.30660.1282233718285.JavaMail.root@gallium.mathforum.org>... 
Subject: find the column index of the first occurance of a value in each row From: Sean Date: 19 Aug, 2010 18:10:26 Message: 8 of 18 
"Matt Fig" <spamanon@yahoo.com> wrote in message <i4jque$du4$1@fred.mathworks.com>... 
Subject: find the column index of the first occurance of a value in each row From: Sean Date: 19 Aug, 2010 18:18:23 Message: 9 of 18 
"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i4js2i$suu$1@fred.mathworks.com>... 
Subject: find the column index of the first occurance of a value in each row From: Matt Fig Date: 19 Aug, 2010 18:23:20 Message: 10 of 18 
"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message 
Subject: find the column index of the first occurance of a value in each From: metaug Date: 19 Aug, 2010 18:41:51 Message: 11 of 18 
Thanks Sean and Mike for your help! Mike, it seems that the naive FOR loop has advantange unless the column size is small. I am using R2009b: 
Subject: find the column index of the first occurance of a value in each From: metaug Date: 19 Aug, 2010 18:52:24 Message: 12 of 18 
Thanks, Bruno. It not only does what I want, but more! 
Subject: find the column index of the first occurance of a value in each From: Bruno Luong Date: 19 Aug, 2010 19:05:41 Message: 13 of 18 
You can't use FIRST option with FIND, because it does work globally, and not rowwise. 
Subject: find the column index of the first occurance of a value in each From: Romain W Date: 10 May, 2013 11:35:10 Message: 14 of 18 
Hi Bruno, 
Subject: find the column index of the first occurance of a value in each From: Bruno Luong Date: 10 May, 2013 11:53:09 Message: 15 of 18 
"Romain W" wrote in message <kmim1e$rb1$1@newscl01ah.mathworks.com>... 
Subject: find the column index of the first occurance of a value in each From: Romain W Date: 10 May, 2013 12:28:10 Message: 16 of 18 
Sorry for the lack of details provided to your crystal ball input. But between us, crystal balls are becoming more and more obsolete these days. 
Subject: find the column index of the first occurance of a value in each From: Bruno Luong Date: 10 May, 2013 12:44:11 Message: 17 of 18 
Try to replace the definition in line #30 of the code find1dmex.c as bellow, then recompile the code (run installation script) 
Subject: find the column index of the first occurance of a value in each From: Romain W Date: 10 May, 2013 13:01:09 Message: 18 of 18 
Neattt, this does work like a charm and will speed up my code, again thank you very much for your help. 
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.