|
Hi Mike
As Nasser wrote, there are more elegant ways to solve this without a loop.
A one-line example would be:
A = shiftdim(reshape(1:m*n,n,m),1);
Regards
Sebastian Arslanogullari
"Mike M" <mccain1976@gmail.com> wrote in message <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.
|