In general, Julia is much more picky about what types of things can be used 
in if statements and && or || conditions than Matlab is.  They must be 
Bools in Julia, whereas Matlab tries to convert things to a scalar logical 
value.

Crazily enough, one of the things that Matlab converts to a scalar logical 
value (albeit not in && or || expressions) is a logical mask.  In Julia, 
you must explicitly convert the mask (a BitArray) to a Bool by calling 
`all` (Matlab's behavior) or `any`.  Check main, line 49.  See the 
documentation for more 
details: 
http://docs.julialang.org/en/latest/manual/control-flow/?highlight=bool#man-conditional-evaluation

Also note that braces don't denote scope, but rather create Any-typed 
arrays.  You don't want to be using them within your if blocks.

On Wednesday, April 23, 2014 4:16:52 PM UTC-4, Isaac wrote:
>
>
> Hi All,
>
>  I am a new Julia-user and meet a problem when I transfer the Matlab code 
> to Julia. I always get the error:type non-boolean (BitArray(1)) used in 
> boolean context. Can anyone help me check the code and solve this problem? 
> The codes have been attached.
> I am using the julia-0.3.0-win64 binary release. 
> Any suggestions and comments would be highly appreciated.
>
> Cheers,
> Isaac
>
> <http://www.google.nl/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCsQFjAA&url=http%3A%2F%2Fforum.wordreference.com%2Fshowthread.php%3Ft%3D2248185%26langid%3D22&ei=Ih9YU4-UJM3JOaCjgKAP&usg=AFQjCNHQ9d3MxWGbJ6kVa5WXzgnDQ1VBRQ&sig2=fFKs_1zFpZD67HrDPpH8Mg>
>

Reply via email to