Constant variable

조회 수: 2 (최근 30일)
justin
justin 2012년 3월 19일
To my first question, I need a code that displays all the constant variables that are atleast 5 in a row excluding 0. The first code shows only the max constant and includes 0. Any help would be great. Thanks
  댓글 수: 1
the cyclist
the cyclist 2012년 3월 19일
If you would like people here to spend some thoughtful time trying to answer your question, you should spend more time making your question as clear and complete as possible. Personally, I don't really know what you are asking for. If English is not your first language, you might want to get someone to help with that, if you are able to.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jonathan Sullivan
Jonathan Sullivan 2012년 3월 19일
Justin. You'll want a very handy function, findseq. It can be downloaded on the file exchange. http://www.mathworks.com/matlabcentral/fileexchange/28113-findseq
The code you'll have to use is as follows:
[vals, start, stop, len] = findseq(A);
len(vals == 0) = -inf; % Exclude 0s
ind = (len >= 5); % Find the ones with 5 or more values.
vals(ind) % Report the value
start(ind) % Report the start index
stop(ind) % Report the stop index
len(ind) % Report the length

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by