Get row no by which the other row is less

조회 수: 1 (최근 30일)
Tha saliem
Tha saliem 2018년 1월 1일
댓글: Star Strider 2018년 1월 2일
hey
I have following cell array which is obtained by comparison of row's elements (if column element of row1 is less than row2 than result is 1 otherwise 0). Row is considered as less if all elements of that row are 1. Now I want to get the element by which that row is less. For example if row2 is less than row1 then I want '1' as answer.
A{1,1} = [1,0,1,1,1,0,1,1,0; 1,1,1,1,1,1,1,1,1]
kindly help.
  댓글 수: 1
Tha saliem
Tha saliem 2018년 1월 1일
In simple words if some element at row 2 is less than an element in row 1 then how can I get the row no of element by which it is less like here it is 1.

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

채택된 답변

Star Strider
Star Strider 2018년 1월 1일
I am not certain what you are asking, since there appear to be two different requests.
Try this:
A{1,1} = [1,0,1,1,1,0,1,1,0; 1,1,1,1,1,1,1,1,1];
AllColumnsLess = cellfun(@(x) all(x,2), A, 'UniformOutput',false)
AllCols = [AllColumnsLess{:}]
[FindRowsLessThan,FindColsLessThan] = cellfun(@find, A', 'UniformOutput',false)
FindRows = [FindRowsLessThan{:}]
FindCols = [FindColsLessThan{:}]
The ‘AllColumnsLess’ returns 1 if the condition is true for all elements in the vector (defined here as row vectors).
The find call returns the row and column indices for the non-zero elements in ‘A’. See the documentation for the find and all functions for details on how they work and what outputs they return.
  댓글 수: 2
Tha saliem
Tha saliem 2018년 1월 2일
Hey Thank You so much for your helping. I got the idea of doing it.
Star Strider
Star Strider 2018년 1월 2일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by