How do I find the first value which is <1 in every column of a matrix?

4 comentarios

Cedric
Cedric el 20 de Ag. de 2015
Editada: Cedric el 20 de Ag. de 2015
Do you need row indices or values? Do all columns have such an element or are there columns with all elements >= 1?
Cedric
Cedric el 3 de Sept. de 2015
Assuming that all columns have at least one element <1, here is one way:
>> X = rand( 6, 4 ) + 0.5 ; X(end,:) = 0.1 ; X % Build test case.
X =
1.1557 1.2431 0.7769 1.4502
0.5357 0.8922 0.5462 0.5344
1.3491 1.1555 0.5971 0.9387
1.4340 0.6712 1.3235 0.8816
1.1787 1.2060 1.1948 1.2655
0.1000 0.1000 0.1000 0.1000
>> firstLt1 = arrayfun( @(c)X(find(X(:,c)<1, 1), c), 1:size(X,2) )
firstLt1 =
0.5357 0.8922 0.7769 0.5344
If some column(s) may not have any element < 1, you can do the following instead:
>> firstLt1 = arrayfun( @(c)X(find(X(:,c)<1, 1), c), 1:size(X,2), 'UniformOutput', false ) ;
which outputs a cell array. Columns of X with no element < 1 lead to cells that contain empty arrays.
Image Analyst
Image Analyst el 3 de Sept. de 2015
Cedric
Cedric el 3 de Sept. de 2015
Editada: Cedric el 3 de Sept. de 2015
Math puns are the first sine of madness!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 20 de Ag. de 2015

Editada:

el 3 de Sept. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by