1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Matlab help

  1. Jan 20, 2009 #1
    1. The problem statement, all variables and given/known data
    switch statements. y is an integer number. Use a switch statement to set B equal to one of the following values: true, false, or the vector [1 0 1]. If y is {1,2,3,5,7}, then set B to true. If y is {4, 6, 8, 10}, then set B to false. If y is neither, then set B to the vector [1 0 1]. You must use a switch statement to solve this problem and your answer should be stored in the variable named "B".

    2. Relevant equations

    3. The attempt at a solution
    switch B
    case '{1,2,3,5,7}'
    case '{4, 6, 8, 10}'
    y=[1 0 1]

    i tried that and it said it was wrong. a file was provided that tells you if its wrong.
  2. jcsd
  3. Jan 20, 2009 #2
    I believe you want your switch to be the criteria you are comparing, ie. y and your statement following the case to be B (the variable you are assigning a value to).

    Switch y

    case '{1,2,3,5,7}'
    B = true
    case '{4,6,8,10}'
    B = false
  4. Jan 20, 2009 #3
    never mind i figured it out.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook