Results 1 to 2 of 2

Math Help - Creating a loop in Matlab help

  1. #1
    Junior Member
    Joined
    Feb 2008
    Posts
    64

    Creating a loop in Matlab help

    I am trying to create a loop in matlab that allows me to create a sequence of numbers but is ended when the number 0 is entered, i have done this so far but i dont know how to go further.

    a=input('a=');
    while a~=0
    b=input(
    'b=');
    if b~=0
    c=[a b];
    else b==0;
    break
    end
    end

    i want the code to allow me to add as many numbers to the sequence until i enter the value 0
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Code:
    c=[];
    a=input('a=');
    while a~=0
     c=[c,a]
     a=input('a=');
    end
    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Matlab question! Help! Infinite loop.
    Posted in the Math Software Forum
    Replies: 3
    Last Post: June 30th 2010, 03:07 AM
  2. Matlab while loop, Please help!
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 23rd 2010, 02:14 AM
  3. help with MATLAB questdlg loop
    Posted in the Math Software Forum
    Replies: 1
    Last Post: March 7th 2010, 10:23 AM
  4. Matlab While Loop Help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: March 8th 2009, 08:50 PM
  5. Matlab loop help
    Posted in the Math Software Forum
    Replies: 2
    Last Post: July 20th 2008, 11:47 AM

Search Tags


/mathhelpforum @mathhelpforum