Get row no where comparison gives 1

Hey i have a cell array:
A={[4x9 cell],[3x9 cell],[2x9 cell]}
A{1,1}= [1,-0.03,0.1,1.3,0,0.23,1,0,0.2; 1,0.6,0.14,2,0,0.6,0.6,0,0.6; 1,-0.15,0,1.4,0,0.35,1,0,0.38; 2,-0.2,0.18,3,0,0.4,0,0,0.4]; similarly values for A{1,2} and A{1,3}
I have compared each row of A{1,1} with every other row in A{1,1} using
A(1:end-1,:)<A(2:end,:)
Now what I want to find is that how can I get the row no's which are being compared at a particular time. For example if row 1 and row 2 are being compared how can I get 1 and 2 in result.
I want to store all elements where result of comparison is 1. for example if row 1 and row 4 gives 1 in result then I want to store the row no where the result is 1 ( like 1 and 4 in this example).
please help.

 Accepted Answer

repmat((1:size(A,1)-1).', 1, size(A,2)) .* (A(1:end-1,:)<A(2:end,:))
which would give you
0 1 1 1 0 1 0 0 1
0 0 0 0 0 0 2 0 0
3 0 3 3 0 3 0 0 3
for whatever good that would do you.

10 Comments

Hey thank you for your answer. Actually I want to get just the row no where comparison is 1. Like if i am comparing row 2 and row 4 and answer is 1. Then i want to store indexes of both these rows.
Like if we just talk about single elements stored in some array. if I compare 2<5 and answer is true. I want rows no of where 2 and 5 are stored in array. So i will apply the same concept to rows.
Each row comparison gives a vector of results. When you are "comparing row 2 and row 4 and answer is 1", what does that mean? Does it mean you want 1 if all of the elements of row 2 are less than the corresponding elements in row 4? Does it mean you want 1 if at least one of the elements in row 2 is less than the corresponding elements in row 4? Does it mean that you want 1 if the maximum value in row 2 is less than the minimum value in row 4?
Tha saliem
Tha saliem on 2 Jan 2018
Edited: Tha saliem on 2 Jan 2018
Yes it means 1 if all of the elements of row 2 are less than elements of row 4.
All of the elements of row 2 are less than the corresponding elements of row 4? Or all of the elements of row 2 are less than the minimum of row 4? Or all of the elements of row 2 are less than the maximum of row 4?
All of the elements of row 2 are less than the corresponding elements of row 4
find( all( A(1:end-1,:)<A(2:end,:), 2) )
Thank you for your time. Actually i have tried using find but how can i get the row no that are being compared at a particular time?
The output of find() is the row number minus 1, so just add 1.
Thank You so much for helping.

Sign in to comment.

More Answers (0)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!