Curious
Posts:
2,063
Registered:
12/6/04


Re: How to create a matrix with increasing power?
Posted:
Feb 21, 2014 5:03 PM


"Sven " <svendotholcombe@gmaildot.com> wrote in message <le8g3t$7kg$1@newscl01ah.mathworks.com>... > "Timothy Liang" <timothy.tliang@gmail.com> wrote in message <le8e48$1uu$1@newscl01ah.mathworks.com>... > > I just started to learn how to use matlab... Just a simply question... > > > > Is there a simple way create a matrix like this? > > x= 1, 2, 3, 4, 5 > > > > matrix X=1^0 1^1 1^2 1^3 > > 2^0 2^1 2^2 2^3 > > 3... > > 4... > > 5... > > > > Thanks!! > > Yep, try this: > > bsxfun(@power, 0:5, (1:5)') > ans = > > 0 1 2 3 4 5 > 0 1 4 9 16 25 > 0 1 8 27 64 125 > 0 1 16 81 256 625 > 0 1 32 243 1024 3125
I don't think this is what Timothy asked for.
If I understand the OP he wants a 4X5 matrix where given:
x = 1:5 y = 10^(0:3)
for ii = 1:length(x) X(:,ii) = x(ii)*y; end
I don't have MATLAB installed on this computer, but the result should be: X= [ 1 1 2 3 1 2 4 8 1 3 9 27 1 4 16 64 1 5 25 125]
which is what I believe the OP asked for. (Maybe its transposed.)
I know there are more MATLAB efficient ways, but Timothy did ask for a SIMPLE way.

