How to pick the elements in a vector with row coordinates satisfying a criterion determined by another vector?
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    MRC
 am 28 Nov. 2013
  
    
    
    
    
    Beantwortet: Andrei Bobrov
      
      
 am 28 Nov. 2013
            Hi, I have a column vector A reporting the first m natural numbers, each of them repeated an arbitrary number of times, e.g.
A=[1;1;2;2;2;3;4;4;4;4];
and a column vector B reporting the first n natural numbers, n>=m, each of them repeated an arbitrary number of times, e.g.
B=[1;2;3;3;3;4;5;5;6;7];
I want to obtain a column vector C reporting the elements of B with row coordinates equal to the row coordinates of each natural number last repetition in A. In the example:
C=[B(2);B(5); B(6); B(10)];
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
  Roger Stafford
      
      
 am 28 Nov. 2013
         C = B(find([diff(A)~=0,true]));
Note that for this to work, B should have at least as many elements as A.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


