Effacer les filtres
Effacer les filtres

find a value in a matrix

2 vues (au cours des 30 derniers jours)
fede
fede le 23 Sep 2015
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

Réponse acceptée

Nobel Mondal
Nobel Mondal le 23 Sep 2015
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 commentaires
Nobel Mondal
Nobel Mondal le 23 Sep 2015
Modifié(e) : Nobel Mondal le 23 Sep 2015
Is this what you're looking for?
>> matchValues = inputMat(inputMat > -2);
Mario Bocanegra
Mario Bocanegra le 4 Sep 2021
This worked! Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by