comparing numbers on the same vector
Mostra commenti meno recenti
hi, i have vector
x=[1 ;5; 20; 10; 15 ;30];
i want to have
y=[1 ;1;1;0;0;1];
such that if the number is bigger than the maximum number (before him) i get 1 else i get 0
here is my try
for i=x(:)
if i> max(x(1:i-1))
y(i)=1 ;
else y(i)=0 ;
end
end
but i know that something wrong with max(x(1:i-1))
Risposta accettata
Più risposte (1)
Andrei Bobrov
il 7 Apr 2016
out = all(bsxfun(@ge,x,x') + triu(ones(numel(x)),1),2);
1 Commento
jean claude
il 7 Apr 2016
Categorie
Scopri di più su Time Series Events in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!