Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!


  1. Jul 16, 2008 #1
    What is wrong with this statement in an 'if' block?

    if ((scalar1 == 0) || (scalar2 == 0) || (scalar3) == 0 || (scalar4 == 0))

    I basically want to say: if any of the four scalars are individually equal to zero, then execute the subsequent statements.

    I receive the following error in the command line:
    Operands to the || and && operators must be convertible to logical scalar values.

    Any suggestions?
  2. jcsd
  3. Jul 16, 2008 #2


    Staff: Mentor

    First, thanks for an exceedingly rare Matlab question that cannot be answered "rtfm" :smile:

    It looks to me like the problem is the parentheses around scalar3


    instead of

  4. Jul 16, 2008 #3
    You know, I thought I had scoured the whole line for a possible mistake. I swore that there wasn't one...but thanks for pointing that out. Wow, I feel like a fool, but at least I can laugh about it now.
  5. Jul 16, 2008 #4
    Eyes like a hawk.:smile:

    I spent a good ten minutes looking at the question while trying to figure out why the code wouldn't work. Then I noticed the brackets!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook