필터 지우기
필터 지우기

How to add another condition for the indexing of certain elements in an array.

조회 수: 1 (최근 30일)
Abdul Rehman
Abdul Rehman 2020년 5월 10일
댓글: KSSV 2020년 5월 11일
I am using this code to find the index of elements having maximum value in each row of a matrix A
for ii=1:row % row is the number of rows in the matrix A
[ii1,jj1] = find(M==max(M(ii,:)));
[indices]=[indices;ii1,jj1];
Now, I want to find those elements that fullfill another condition i.e. they have minimum value in thier respective column. How can I achieve that.
I have just started learning Matlab and any guidline will be appreciated. Also, I do not need the code only guidline or a way to do this task. Thanks in advance.

답변 (1개)

KSSV
KSSV 2020년 5월 10일
Read about max and min. You can specify the dimension i.e you want max, min along row or column. If A is your matrix.
You can max element in every column using
[val,idx] =max(A) ;
[val,idx] = max(A,[],1) ;
The above steps are same.
If you want to get max element in every row use:
[val,idx] = max(A,[],2) ;
Same is the case with min.
  댓글 수: 4
Abdul Rehman
Abdul Rehman 2020년 5월 11일
But max and min will only give us the index and vlaue of the first maximum and minimum element in an array. I need to find all values of maximum or minimum elements i.e. if a vlaue repeats in a row i wanted both its indeces.
Thanks for your time.
KSSV
KSSV 2020년 5월 11일
You sort the array/ matrix and pick the values you want.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by