How to search the continuous values with maximal size in a vector ?
Show older comments
How to search continuous values in a vector,meanwhile,the size of the continuous values is the largest? For example,
a=[1 2 3 4 5 6 7 11 13 14 15 18 19]
Here the answer should be
ans=[1 2 3 4 5 6 7]
Help me to find the answer for vector of size n. I want to use this to detect a portion which is linear in a curve. Is there some function in MATLAB which could do this work? Thanks.
Accepted Answer
More Answers (1)
Alessandro Renna
on 27 Apr 2013
I wrote this function:
function y=continuous(a)
n=length(a);
for i=1:n-1
if diff(a(i:i+1))==1
z(i)=a(i);
z(i+1)=a(i+1);
end
end
y=z(z~=0);
In this way, if a is [1 2 3 4 5 6 7 11 13 14 15 18 19], the result y will be only the continuous part of a, [1 2 3 4 5 6 7 13 14 15 18 19].
1 Comment
sandberry
on 28 Apr 2013
Categories
Find more on National Instruments Frame Grabbers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!