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))

 채택된 답변

Roger Stafford
Roger Stafford 2016년 4월 6일

0 개 추천

y(1) = true;
for k = 2:length(x)
y(k) = (max(x(1:k-1))<x(k));
end
y = double(y);

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 4월 7일

0 개 추천

out = all(bsxfun(@ge,x,x') + triu(ones(numel(x)),1),2);

카테고리

도움말 센터File Exchange에서 Time Series Events에 대해 자세히 알아보기

제품

태그

질문:

2016년 4월 6일

댓글:

2016년 4월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by