find a value in a matrix

조회 수: 22 (최근 30일)
fede
fede 2015년 9월 23일
댓글: Mario Bocanegra 2021년 9월 4일
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

채택된 답변

Nobel Mondal
Nobel Mondal 2015년 9월 23일
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
Nobel Mondal
Nobel Mondal 2015년 9월 23일
편집: Nobel Mondal 2015년 9월 23일
Is this what you're looking for?
>> matchValues = inputMat(inputMat > -2);
Mario Bocanegra
Mario Bocanegra 2021년 9월 4일
This worked! Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by