help-octave
[Top][All Lists]
Advanced

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

Re: Can't fix this error, please help.


From: Kai Torben Ohlhus
Subject: Re: Can't fix this error, please help.
Date: Tue, 31 Dec 2019 11:53:45 +0900
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1

On 12/31/19 11:42 AM, ArTicMyth wrote:
> Hey guys, i can't seem to fix this error and i was hoping one of you could
> help me :D
> (It shows the error when i choose the second option)
> <https://octave.1599824.n4.nabble.com/file/t373591/Untitled.png> 
> <https://octave.1599824.n4.nabble.com/file/t373591/Untitled1.png> 
> <https://octave.1599824.n4.nabble.com/file/t373591/Untitled2.png> 
> 
> 

Please do not send only screenshots of your code.  The important lines are

   x = input ("Input: ", "s");
   if (x == "something")
     disp ("something")
   else
     disp ("else")
   endif

which result for the input "blub" in the following error:

   error: blub: mx_el_eq: nonconformant arguments (op1 is 1x4, op2 is 1x9)
   error: called from
    buggy at line 2 column 1


The solution is to use `strcmp()` [1] for string comparisons.  Octave
treats your input `x` as array of char (like C) and not as some string
class (like C++).

   x = input ("Input: ", "s");
   if strcmp (x, "something")
     disp ("something")
   else
     disp ("else")
   endif

HTH,
Kai


[1] https://octave.org/doc/v5.1.0/XREFstrcmp.html



reply via email to

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