1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development Basic MATLAB/Programming Question

Discussion in 'Software' started by felix the cat, 25 Mar 2013.

  1. felix the cat

    felix the cat Spaceman Spiff

    Joined:
    11 Jan 2002
    Posts:
    4,914
    Likes Received:
    11
    Hello All,

    My girlfriend has asked me to give her a hand with some Matlab, and I am afraid my programming days are long gone/my mind has gone blank.

    This ought to be a really simple loop/if statement - basically the experiment she wants to run has two possible conditions, and she has the script for these two conditions - so she would like (for example) to run condition A 5 times, followed by B 5 times, followed by A 5 times, etc.

    So how do I get the following to work (as I don't think MATLAB goes through each entry of a matrix).

    exp = [A A A A A B B B B B A A A A A]

    if exp = A

    ...code
    code
    code
    code...

    else if exp = B

    ...code
    code
    code
    code
    code...

    Does that make sense? Is this possible without "breaking" the program up into seperate .m files?

    Thanks for any help/thoughts/STFU N00b! :)
     
  2. Valo

    Valo Minimodder

    Joined:
    11 Aug 2004
    Posts:
    1,182
    Likes Received:
    22
    for i=1:len(exp)

    if exp == A
    blah
    else if exp ==B
    blah#2

    Although as far as my memory goes I think matlab has python-like iteration over array elements
     
  3. felix the cat

    felix the cat Spaceman Spiff

    Joined:
    11 Jan 2002
    Posts:
    4,914
    Likes Received:
    11
    Thanks Valo for the really fast reply!

    What do you mean by "pytho like iteration over array elements"?
     

Share This Page