Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Maxtrix generation with nested loops
Date: Fri, 4 May 2012 02:46:50 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 47
Message-ID: <jnvfuq$p3$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1336099610 803 172.30.248.47 (4 May 2012 02:46:50 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 4 May 2012 02:46:50 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3470412
Xref: news.mathworks.com comp.soft-sys.matlab:766787

I am having a bit of a problem I am attempting to generate a matrix using a pair of while loops and then mesh plot that matrix. For some reason it seems that one of my variables doesn't change along with its increment and I can't for the life of me figure out why. Here is my code:
    mz=[]
    my2=[]
    i=1
    j=1
    xv1=x(i)
    yv1=y(j)
    y2=x.^2+y.^2
    while i<xmax+1
        while j<ymax+1
            yv2=y2(x(i),y(j))
            my2(end+1)=yv2
            j=j+1
        end
        mz(i,:)=my2
        i=i+1
    end 
    mesh(mz)
end

The expected matrix is 
     2     5    10    17    26    37    50    65    82   101
     5     8    13    20    29    40    53    68    85   104
    10    13    18    25    34    45    58    73    90   109
    17    20    25    32    41    52    65    80    97   116
    26    29    34    41    50    61    74    89   106   125
    37    40    45    52    61    72    85   100   117   136
    50    53    58    65    74    85    98   113   130   149
    65    68    73    80    89   100   113   128   145   164
    82    85    90    97   106   117   130   145   162   181
   101   104   109   116   125   136   149   164   181   200

The matrix I am getting is
     2     8    18    32    50    72    98   128   162   200
     2     8    18    32    50    72    98   128   162   200
     2     8    18    32    50    72    98   128   162   200
     2     8    18    32    50    72    98   128   162   200
     2     8    18    32    50    72    98   128   162   200
     2     8    18    32    50    72    98   128   162   200
     2     8    18    32    50    72    98   128   162   200
     2     8    18    32    50    72    98   128   162   200
     2     8    18    32    50    72    98   128   162   200
     2     8    18    32    50    72    98   128   162   200

It looks to me like the x value isn't changing for i

Thanks in advance.