Results 1 to 7 of 7

Math Help - Matlab - Storing a row for a matrix?

  1. #1
    Newbie
    Joined
    Mar 2010
    Posts
    11

    Matlab - Storing a row for a matrix?

    Hey all, I've got a little question, Hoping I can make myself clear.

    I'm building a 'For' function X times (Inside a while loop) in order to sum it all up to a matrix (every 'for' loop is one row in the matrix).
    The problem - Everytime It's running the 'for' function, it's deleting the previous for function it created (It's quite obvious, cuz i'm using the same variable).
    Is there any function to store every run of the 'for' function in a new variable in order to sum it all up in the end ?

    Hopes it's clear.
    Thanks.
    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 Geomorphologist View Post
    Hey all, I've got a little question, Hoping I can make myself clear.

    I'm building a 'For' function X times (Inside a while loop) in order to sum it all up to a matrix (every 'for' loop is one row in the matrix).
    The problem - Everytime It's running the 'for' function, it's deleting the previous for function it created (It's quite obvious, cuz i'm using the same variable).
    Is there any function to store every run of the 'for' function in a new variable in order to sum it all up in the end ?

    Hopes it's clear.
    Thanks.
    Create an array to hold the results and store them in the array as you compute them.

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Mar 2010
    Posts
    11
    Quote Originally Posted by CaptainBlack View Post
    Create an array to hold the results and store them in the array as you compute them.

    CB
    Thanks for your reply.
    Is there a special way to do that ? If i'm creating a matrix : 'matrix = [a]' It will still replace the 'a' every time. Am I missing something ?
    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 Geomorphologist View Post
    Thanks for your reply.
    Is there a special way to do that ? If i'm creating a matrix : 'matrix = [a]' It will still replace the 'a' every time. Am I missing something ?
    Code:
    matrix=zeros(1,10);
    for i=1:10
    
       .. do calculations for a
    
      matrix[i]=a;
    end
    CB
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Mar 2010
    Posts
    11
    Quote Originally Posted by CaptainBlack View Post
    Code:
    matrix=zeros(1,10);
    for i=1:10
    
       .. do calculations for a
    
      matrix[i]=a;
    end
    CB
    I really appreciate your help, but still - I doesn't work
    There's the code I created , It's working fine, but not storing every input like I stated before (the code is without your addons):

    Code:
    c = input('Please enter number of columns in Matrix: '); 
    d = input('Please enter number of rows in Matrix: ');
    e=d;
    while (e > 0)
        e=e-1;
            for b = 1:1:c
            a(b) = input('Enter a number for the matrix: ');
            end
       
    end
    Can you be more specific ?
    Thank you very very very much!
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Geomorphologist View Post
    I really appreciate your help, but still - I doesn't work
    There's the code I created , It's working fine, but not storing every input like I stated before (the code is without your addons):

    Code:
    c = input('Please enter number of columns in Matrix: '); 
    d = input('Please enter number of rows in Matrix: ');
    e=d;
    while (e > 0)
        e=e-1;
            for b = 1:1:c
            a(b) = input('Enter a number for the matrix: ');
            end
       
    end
    Can you be more specific ?
    Thank you very very very much!
    Code:
    c = input('Please enter number of columns in Matrix: '); 
    d = input('Please enter number of rows in Matrix: ');
    e=d;
    
    a=zeros(c,d)
    
    for e=d:-1:1
     
            for b = 1:1:c
                a(b,e) = input('Enter a number for the matrix: ');
            end
       
    end
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Newbie
    Joined
    Mar 2010
    Posts
    11
    Thank you very much, working like a charm (I flipped the ' a(b,e) = input' in order for it to work properly).
    Thank you very much, I'm quite new in Matlab and I see I complicated it too much with the While loop.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. matlab matrix help
    Posted in the Math Software Forum
    Replies: 3
    Last Post: May 18th 2010, 12:21 AM
  2. Matlab Matrix Compare
    Posted in the Math Software Forum
    Replies: 1
    Last Post: November 16th 2009, 09:00 PM
  3. Matlab ( Matrix )
    Posted in the Math Software Forum
    Replies: 2
    Last Post: April 6th 2009, 01:32 AM
  4. Matlab help ........Matrix
    Posted in the Math Software Forum
    Replies: 0
    Last Post: April 4th 2009, 06:05 AM
  5. Storing Formulae
    Posted in the Calculators Forum
    Replies: 4
    Last Post: April 3rd 2007, 04:35 PM

Search Tags


/mathhelpforum @mathhelpforum