In a row matrix how to compare the adjecent elements . for example A= 25 14 16 7 25, NOW FIRST ELEMENT 25 as to compare with each element and comarision should stop when it meats larger or equal number i.e., 25 wii stop at 25 in the A

for example A= 25 14 16 7 25, NOW FIRST ELEMENT 25 as to compare with each element and comarision should stop when it meats larger or equal number i.e., 25 wii stop at 25 in the A

 Accepted Answer

next_idx = find(A(2:end) >= A(1)) + 1;
This will be [] if there were no locations that met the condition.

6 Comments

ya its working bt i want next number to do the same comparision till end of the row i,e., 14 shud compare with adjecent and 16 so on please help me for that
while comparing 14 with next number 16 is greater than 14 so comparision shud stop thr and now start with 16 again compare with next number. if number meets greater than it the loop shud stop and next number comparision shud start
sum(cumprod(~triu(bsxfun(@le, A(:), A(:).'),1),2),2) + 1
Note: in the case where there are no later matches, the output value will be length(A)+1 . This will always be the case for the last result, as the last value can never be greater than or equal to the non-existent entries that do not follow the last value.
its error
??? Error using ==> cumprod First argument must be single or double.
Error in ==> trail_2 at 18 w=sum(cumprod(~triu(bsxfun(@le, A(:), A(:).'),1),2),2) + 1 not working

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!