help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: find subvector with findstr / strfind

 From: Nicholas Jankowski Subject: Re: find subvector with findstr / strfind Date: Wed, 17 Feb 2016 09:33:57 -0500

On Wed, Feb 17, 2016 at 8:13 AM, inor0627 wrote:
Hello,

I used to locate a sequence of numbers in a longer vector via findstr(),
e.g.
findstr( [3 4 5 3 4] , [3 4] )
ans =  1   4.
Today I came across the information that findstr() is scheduled for
deprecation and one should use strfind() instead.

However, trying
strfind( [3 4 5 3 4] , [3 4] )
results in:
error: strfind: PATTERN must be a string or cell array of strings.

Will non-strings be supported in a future version of strfind() or should I
use another approach for finding subvectors?

My octave version is 4.0.0 on Win7.

Best regards,
Ingo

PS: In Matlab 2012 strfind() as well as findstr() can be used with
non-strings.

Just to verify, Matlab 2015b still gives:

>> strfind([3 4 5 3 4],[3 4])

ans =
1     4

this does not appear anywhere in the help documentation though, which calls for the input to be a string. Methinks Matlab is automatically doing a type conversion, and either strings are turned into numeric arrays and searched for the pattern, or the numeric array is converted to a char array and then handled as a string.

I'm thinking the former, because:

strfind([3.1 4 5 3.2 4],[3.1 4])
ans =
1

and i'm pretty sure char conversion truncates the decimals.

All that said, Octave normally goes with following the declared function properties. chasing down every undocumented matlab quirk can become an impossible task as mathworks could change things next version with no indication or regression announcement.

nick j

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]