

I'm writing a fairly simple plotting function in Octave with a number of filenames, and I have a number of string comparison commands to sort the datasets. The problem is, the program kept behaving oddly, and after some investigation, it seems that strcmp was the culprit and is acting completely randomly with respect to the documentation.
Examples:
strcmp ('vent', 'vent')
returns
error: A(J,I): row index out of bounds; value 118 out of bound 114
and
strcmp ('g_90', 'vent')
returns a 4x4 unit matrix.
meanwhile
strcmp ('g_90', 'nograv')
returns a 4x6 matrix with 1's in the first and last columns and 0's everywhere else.
I have a few other examples, but in general, strcmp is not reliably comparing strings.

Administrator

On Oct 21, 2012, at 11:10 AM, Mumble07 < [hidden email]> wrote:
> I'm writing a fairly simple plotting function in Octave with a number of
> filenames, and I have a number of string comparison commands to sort the
> datasets. The problem is, the program kept behaving oddly, and after some
> investigation, it seems that strcmp was the culprit and is acting completely
> randomly with respect to the documentation.
>
> Examples:
>
> strcmp ('vent', 'vent')
>
> returns
>
> error: A(J,I): row index out of bounds; value 118 out of bound 114
>
> and
>
> strcmp ('g_90', 'vent')
>
> returns a 4x4 unit matrix.
>
> meanwhile
>
> strcmp ('g_90', 'nograv')
>
> returns a 4x6 matrix with 1's in the first and last columns and 0's
> everywhere else.
>
> I have a few other examples, but in general, strcmp is not reliably
> comparing strings.
What version of Octave are you running? And what does "which strcmp" return?
Ben
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


I'm running octave version 3.6.2, the latest version on the Suse repository.
'which strcmp' returns 'strcmp is a builtin function'.


On 22 Oct 2012, at 12:38, Mumble07 wrote:
> I'm running octave version 3.6.2, the latest version on the Suse repository.
> 'which strcmp' returns 'strcmp is a builtin function'.
You should report this as a packaging bug to the Suse repository maintainers,
your system seems to be badly broken.
With the same Octave version buil from sources on Scientific Linux I get:
octave:1> version
ans = 3.6.2
octave:2> strcmp ('vent', 'vent')
ans = 1
octave:3> strcmp ('g_90', 'vent')
ans = 0
octave:4> strcmp ('g_90', 'nograv')
ans = 0
octave:5>
In Octave sources strcmp with string inputs maps to just:
static bool
strcmp_str_op (const std::string& s1, const std::string& s2, octave_idx_type)
{
return s1 == s2;
}
which is a very basic method in the C++ standard library, I really wonder what can be going wrong here ...
c.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


Am 22.10.2012 13:52, schrieb c.:
> On 22 Oct 2012, at 12:38, Mumble07 wrote:
>
>> I'm running octave version 3.6.2, the latest version on the Suse repository.
>> 'which strcmp' returns 'strcmp is a builtin function'.
> You should report this as a packaging bug to the Suse repository maintainers,
> your system seems to be badly broken.
>
> With the same Octave version buil from sources on Scientific Linux I get:
>
> octave:1> version
> ans = 3.6.2
> octave:2> strcmp ('vent', 'vent')
> ans = 1
> octave:3> strcmp ('g_90', 'vent')
> ans = 0
> octave:4> strcmp ('g_90', 'nograv')
> ans = 0
> octave:5>
>
> In Octave sources strcmp with string inputs maps to just:
>
> static bool
> strcmp_str_op (const std::string& s1, const std::string& s2, octave_idx_type)
> {
> return s1 == s2;
> }
>
> which is a very basic method in the C++ standard library, I really wonder what can be going wrong here ...
>
> c.
>
> _
I have not the simplest problems with this on openSUSE with octave 3.6.2
from the science repository, gives correct results and works.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


Well it's not working for me. Any suggestions on what I should do to resolve it?


Am 22.10.2012 20:31, schrieb Mumble07:
> Well it's not working for me. Any suggestions on what I should do to resolve
> it?
>
Are you using SUSE (which is the enterprise variant) or openSUSE and
which version. From which repository did you install it?
cat /etc/SuSErelease
rpm qi octave
will tell us.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


openSUSE 12.2 (x86_64)
VERSION = 12.2
CODENAME = Mantis
__________________________________
Name : octave
Version : 3.6.2
Release : 2.1.2
Architecture: x86_64
Install Date: ven. 21 sept. 2012 11:55:41 CEST
Group : Productivity/Scientific/Math
Size : 46087899
License : GPL3.0+
Signature : RSA/SHA256, mar. 17 juil. 2012 04:50:40 CEST, Key ID b88b2fd43dbdc284
Source RPM : octave3.6.22.1.2.src.rpm
Build Date : mar. 17 juil. 2012 04:41:57 CEST
Build Host : build21
Relocations : (not relocatable)
Packager : http://bugs.opensuse.orgVendor : openSUSE
URL : http://www.octave.org/Summary : A High Level Programming Language
Description :
Octave is a high level programming language. It is designed for the
solution of numeric problems. There is a command line interface
supplied.
Distribution: openSUSE 12.2
_______________________
Does this help?


Huh. I just went back and tried strcmp in the command line again, and the problem appears to have dissapeared. Since then, I've restarted octave, as well as the terminal instance. Could it have been something wonky in the terminal? I could have sworn I restarted octave several times.


On 22 October 2012 17:44, Mumble07 < [hidden email]> wrote:
> Huh. I just went back and tried strcmp in the command line again, and the
> problem appears to have dissapeared. Since then, I've restarted octave, as
> well as the terminal instance. Could it have been something wonky in the
> terminal? I could have sworn I restarted octave several times.
You probably defined strcmp to be something else. Did you mess up your
load path? Was strcmp a variable name?
 Jordi G. H
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


Am 22.10.2012 23:46, schrieb Jordi Gutiérrez Hermoso:
> On 22 October 2012 17:44, Mumble07 < [hidden email]> wrote:
>> Huh. I just went back and tried strcmp in the command line again, and the
>> problem appears to have dissapeared. Since then, I've restarted octave, as
>> well as the terminal instance. Could it have been something wonky in the
>> terminal? I could have sworn I restarted octave several times.
> You probably defined strcmp to be something else. Did you mess up your
> load path? Was strcmp a variable name?
>
>  Jordi G. H
>
Good catch: Sounds like a possible reason, if I do that then I get such
an error
octave:1> strcmp=1
strcmp = 1
octave:2> strcmp ('g_90', 'vent') error: A(I,J): row index out of
bounds; value 103 out of bound 1
octave:2>
which is a logical consequence.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


On 22 October 2012 17:59, Martin Helm < [hidden email]> wrote:
> Am 22.10.2012 23:46, schrieb Jordi Gutiérrez Hermoso:
>> On 22 October 2012 17:44, Mumble07 < [hidden email]> wrote:
>>> Huh. I just went back and tried strcmp in the command line again, and the
>>> problem appears to have dissapeared. Since then, I've restarted octave, as
>>> well as the terminal instance. Could it have been something wonky in the
>>> terminal? I could have sworn I restarted octave several times.
>> You probably defined strcmp to be something else. Did you mess up your
>> load path? Was strcmp a variable name?
>>
> Good catch: Sounds like a possible reason, if I do that then I get such
> an error
>
> octave:1> strcmp=1
> strcmp = 1
> octave:2> strcmp ('g_90', 'vent') error: A(I,J): row index out of
> bounds; value 103 out of bound 1
> octave:2>
>
> which is a logical consequence.
It appears that citizen Mumble07 defined strcmp to be some
114byatleast118 matrix of zeros and ones and then tried to index
it with strings.
Perhaps there should be some warning about attempting to index
matrices with strings. What does Matlab do if you attempt to do this?
 Jordi G. H.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


On 23 Oct 2012, at 00:05, Jordi Gutiérrez Hermoso wrote:
> What does Matlab do if you attempt to do this?
>
something very similar to Octave:
>> version
ans =
7.5.0.338 (R2007b)
>> strcmp=1;
>> strcmp ('g_90', 'vent')
??? Index exceeds matrix dimensions.
>>
>  Jordi G. H.
c.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave

Administrator

In reply to this post by Jordi Gutiérrez Hermoso2
On Oct 22, 2012, at 6:05 PM, Jordi Gutiérrez Hermoso wrote:
> On 22 October 2012 17:59, Martin Helm < [hidden email]> wrote:
>> Am 22.10.2012 23:46, schrieb Jordi Gutiérrez Hermoso:
>>> On 22 October 2012 17:44, Mumble07 < [hidden email]> wrote:
>>>> Huh. I just went back and tried strcmp in the command line again, and the
>>>> problem appears to have dissapeared. Since then, I've restarted octave, as
>>>> well as the terminal instance. Could it have been something wonky in the
>>>> terminal? I could have sworn I restarted octave several times.
>>> You probably defined strcmp to be something else. Did you mess up your
>>> load path? Was strcmp a variable name?
>>>
>> Good catch: Sounds like a possible reason, if I do that then I get such
>> an error
>>
>> octave:1> strcmp=1
>> strcmp = 1
>> octave:2> strcmp ('g_90', 'vent') error: A(I,J): row index out of
>> bounds; value 103 out of bound 1
>> octave:2>
>>
>> which is a logical consequence.
>
> It appears that citizen Mumble07 defined strcmp to be some
> 114byatleast118 matrix of zeros and ones and then tried to index
> it with strings.
>
> Perhaps there should be some warning about attempting to index
> matrices with strings. What does Matlab do if you attempt to do this?
strcmp = round (rand (114,118));
strcmp ('g_90', 'vent')
ans =
0 1 0 0
1 0 1 0
0 0 1 1
1 0 1 0
Ben
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


Thanks for all the help guys, I should be more mindful of my variables in the future :P


>________________________________
> From: Mumble07 < [hidden email]>
>To: [hidden email]
>Sent: Tuesday, October 23, 2012 12:58 AM
>Subject: Re: Strcmp not behaving as expected
>
>Thanks for all the help guys, I should be more mindful of my variables in the
>future :P
>
>
>
Function redefinition, especially in case of replacing a function with nonfunction, should be accompanied by a warning  regardless what Matlab does.
An example:
"
sergei@amdam2:~/junk> cat n function_redefinition.pl
1 use strict;
2 use warnings;
3
4 sub foo{1}
5 sub foo{2}
sergei@amdam2:~/junk> ~/AFSWD/install/perl5.14.2/bin/perl function_redefinition.pl
Subroutine foo redefined at function_redefinition.pl line 5.
sergei@amdam2:~/junk>
".
Regards,
Sergei.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave

