find a value in a matrix

For example I have the following cell
x1 x2 x3
x1 2 3 4
x2 5 -2 -5
x3 -6 -5 -4
I want to search all variable of matrix > -2, and as output : x1, x2 for example. In my case :
INPUT:find(matrix>-2),
OTUPUT:
X1 X1
X1 X2
X2 X1
X1 X3

 Respuesta aceptada

Nobel Mondal
Nobel Mondal el 23 de Sept. de 2015

1 voto

I wasn't sure if you want the actual output in terms of 'x*' or the corresponding index.
>> inputMat = [2 3 4; 5 -2 -5; -6 -5 -4];
>> [myRow, myCol] = find(inputMat > -2);
>> numericalAns = [myRow myCol];
>> indexNames = {'x1' 'x2' 'x3'};
>> cellFormAns = [indexNames(myRow)' indexNames(myCol)'];

5 comentarios

fede
fede el 23 de Sept. de 2015
Greaaat good job!!! thanks u. Last questions, if I wanto to have also the value of my research, for example:
x1 x2 == 3
Nobel Mondal
Nobel Mondal el 23 de Sept. de 2015
I didn't fully understand your question. Could you please rephrase?
fede
fede el 23 de Sept. de 2015
I want the value of my research. For example I obtain that x1,x2 have a value >-2, and I want another array in which ther'is this value, in this case 3.
Nobel Mondal
Nobel Mondal el 23 de Sept. de 2015
Editada: Nobel Mondal el 23 de Sept. de 2015
Is this what you're looking for?
>> matchValues = inputMat(inputMat > -2);
Mario Bocanegra
Mario Bocanegra el 4 de Sept. de 2021
This worked! Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 23 de Sept. de 2015

Comentada:

el 4 de Sept. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by