"Mayuri " <mayuris@rri.res.in> wrote in message <jjmkgf$s2l$1@newscl01ah.mathworks.com>...
> Thank you very much. This is exactly what I wanted. Where can I find information to better understand hoe the line
> t = (p<=length(A));
> works?
        
First look up in your "Matlab Programming Fundamentals" or similar documents all the references to 1) the logical class, 2) logical operators, 3) logical arrays, 4) relational operators, 5) logical subscripting, and in general anything that has the term 'logical' in it.
For the particular line "t = (p<=length(A))", it generates an array which instead of consisting of numbers, are logical quantities either true or false, a special class in matlab. The array p is an array of numerical indices giving the locations of where the various sorted elements came from. For example, if the 4th element of p is equal to 7 that means that the 7th element of [A,B] ended up as the 4th element after sorting. The logical expression p<=length(A) is true whenever a value of p is found that gives the index of an element that must have come from A because it is less than or equal to the length of A, which came first in [A,B]. Those that indicate a source from B will fail this test and be false.
You should experiment with it on your own and try to verify how it all works by looking at an array before and after sorting and how the index p relates to that. Then you should verify that all the true values in t correspond to elements that were in A and false for all those in B. (Of course use very short A and B for such experiments unless you have lots of time on your hands.)
(Note: One thing to especially remember about logicals is that when they are subjected to a subsequent arithmetic operation they are converted over to the numbers 1 in place of 'true' and 0 in place of 'false'. This is often of great usefulness.)
(End of lecture on logicals.)
Roger Stafford
