Path: news.mathworks.com!newsfeed-00.mathworks.com!solaris.cc.vt.edu!news.vt.edu!news.glorb.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe06.iad.POSTED!7564ea0f!not-for-mail
From: "Nasser M. Abbasi" <nma@12000.org>
Newsgroups: comp.soft-sys.matlab
References: <hcbano$9kc$1@fred.mathworks.com>
Subject: Re: Please take a look at this code and let me know what's wrong
Lines: 37
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3598
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350
X-EsetId: 321EA926BF2033396252
X-EsetScannerBuild: 5929
Message-ID: <DTaGm.3$cU.0@newsfe06.iad>
NNTP-Posting-Host: ncdeodfefpjopplmihjclpliaacepnnh
X-Complaints-To: abuse@charter.net
X-Trace: emlnjhpjaknjmmohadefjppgkgeilljajjgifdaanklgjcooncdeodfefpjopplmmgdmmdanmgdmojgmbpfleebipkijiajhoeggmpchongebilpalljjmnbmpmclkfjbgdoooicbbgjoani
NNTP-Posting-Date: Thu, 29 Oct 2009 06:46:59 UTC
Date: Thu, 29 Oct 2009 01:46:57 -0500
Xref: news.mathworks.com comp.soft-sys.matlab:580850



"Mike M" <mccain1976@gmail.com> wrote in message 
news:hcbano$9kc$1@fred.mathworks.com...
> Here's a "problem" I'm working on:
> m = input('Enter an integer m to represent the number of desired rows:')
> n = input('Enter an integer n to represent the number of desired 
> columns:')
> A = zeros(m:n);
> for i = 1:m
>    for j = 1:n
>        A(i,j) = linspace((i-1)*n+1, (i-1)*n+j, n);
>    end
> end
> A
> It's supposed to create an m x n matrix that goes from 1:n by 1.  In other 
> words, if you enter 3 for m and 3 for n, you should get:
> A = [1,2,3;4,5,6;7,8,9].  Entering 4 would do the same except to 16.  I'm 
> definitely a newbie so I'm not seeing the error.


one way, use loop

m = input('Enter an integer m to represent the number of desired rows:')
n = input('Enter an integer n to represent the number of desired columns:')
A=zeros(m,n);

for i=1:m
    for j=1:n
         A(i,j)=n*(i-1)+j;
    end
end

(could be done witout loop if you really want to)

--Nasser