Results 1 to 6 of 6

Math Help - matlab for loops?

  1. #1
    Junior Member
    Joined
    Feb 2009
    Posts
    29

    matlab for loops?



    So far i have this

    VEC = input('Please type a value that is > 9 and < 21:')
    if VEC < 10 || VEC > 21
    error('Incorrect Input... Quitting!')
    Vec1 = input('Type in a value for the first element:')

    But not sure if I'm on the right track.. Could someone help me with this problem
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Mathhelpz View Post


    So far i have this

    VEC = input('Please type a value that is > 9 and < 21:')
    if VEC < 10 || VEC > 21
    error('Incorrect Input... Quitting!')
    Vec1 = input('Type in a value for the first element:')

    But not sure if I'm on the right track.. Could someone help me with this problem
    Have you tested it?

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Junior Member
    Joined
    Feb 2009
    Posts
    29
    yea,

    this is my script so far

    % initialize the vector
    VEC = [];
    n = 1;

    VEC_length = input('Please type a value that is > 9 and < 21:');
    if VEC_length < 10 || VEC_length > 21
    error('Incorrect Input... Quitting!')
    end

    Vec1 = input('Type in a value for the first element:')

    % Add first element to the vector
    VEC(n)=Vec1;

    % Use a for loop to add more number to the vector
    for i=1:VEC_length
    n=n+1;
    VEC(n)= Vec1 +i;
    end


    I don't really know what to do on step 4? COuld you help me
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Mathhelpz View Post
    yea,

    this is my script so far

    % initialize the vector
    VEC = [];
    n = 1;

    VEC_length = input('Please type a value that is > 9 and < 21:');
    if VEC_length < 10 || VEC_length > 21
    error('Incorrect Input... Quitting!')
    end

    Vec1 = input('Type in a value for the first element:')

    % Add first element to the vector
    VEC(n)=Vec1;

    % Use a for loop to add more number to the vector
    for i=1:VEC_length
    n=n+1;
    VEC(n)= Vec1 +i;
    end


    I don't really know what to do on step 4? COuld you help me
    This is wrong:

    Code:
    VEC_length = input('Please type a value that is > 9 and < 21:');
    if VEC_length < 10 || VEC_length > 21
      error('Incorrect Input... Quitting!')
    end
    Try inputting a value of 21

    CB
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Mathhelpz View Post

    I don't really know what to do on step 4? COuld you help me
    Code:
    if VEC(1)>=25 
      VEC(1)=0;
    end
    
    for k=2:VEC_LENGTH
      VEC(k)=VEC(k-1)+1;
      if VEC(k)>=25
        VEC(k)=0;
      end
    end
    CB
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Junior Member
    Joined
    Feb 2009
    Posts
    29
    thanks for that, i almost finised it =D
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. loops in matlab, plotting matrix elements
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 10th 2011, 10:50 AM
  2. Need help with Matlab (Loops)
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 8th 2011, 01:50 AM
  3. [SOLVED] Matlab plotting help:peicewise with loops
    Posted in the Math Software Forum
    Replies: 4
    Last Post: October 20th 2009, 10:19 PM
  4. While loops
    Posted in the Math Software Forum
    Replies: 3
    Last Post: May 11th 2009, 07:54 PM
  5. While Loops! Help me please!!!!
    Posted in the Discrete Math Forum
    Replies: 3
    Last Post: October 8th 2007, 02:25 PM

Search Tags


/mathhelpforum @mathhelpforum