Using the find() function to find only the first number greater than the given number.

71 visualizaciones (últimos 30 días)
'cell' contains numbers
I want to use the find fucntion like this >>> " find(cell>number) " but i want it to only show the first number that is greater then 'number' and not the rest of the cell.

Respuestas (1)

the cyclist
the cyclist el 31 de Mayo de 2020
Here is one way:
% The threshold number
number = 2;
% Your cell. (Don't name it "cell", which is a MATLAB keyword.)
C = {[1 2]; [2 3]; [4 5]};
% For each cell, the first number greater than the threshold. If none the cell has an empty array.
N = cellfun(@(x)x(find(x>number,1)),C,'UniformOutput',false)
  3 comentarios
Walter Roberson
Walter Roberson el 31 de Mayo de 2020
find(YourArray>number,1)
Note that this will proceed along columns, so for example,
cell = [
0 10
0 0
0 0
5 0]
then find(cell>3,1) would find the 5 rather than the 10
Cameron Tiegs
Cameron Tiegs el 31 de Mayo de 2020
Editada: Cameron Tiegs el 31 de Mayo de 2020
Thanks for the answer. I used your idea and made this, which worked :)
Index = find(C>number,1);

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by