How to force reshape for change elements?

m=input('z= ');
n=m+1;
for i=1:n
x(i)=input(['x',num2str(i),'= '])
for k=0:m
x1=x(i)^k;
end
end
x=reshape(x1,n,n)
But it displays Error using Reshape because my elements are change.
My goal is to reshape my input becomes n×n matrices. When i tried to change
x=reshape(x1,n,[])
For example i input z=2 And input each one,
x1=1
x2=2
x3=3
This just display
x=
1
2
3
But i "want" my result is like this
x=
1 1 1
1 2 4
1 3 9
Notice that in my first column, i raised them to zero, (1^0=1, 2^0=1, 3^0=1)
In my second column, i raised them to one, (1^1=1, 2^1=2, 3^1=3).
And in my last column i squared them as (1^2=1, 2^2=4, 3^2=9)
How to process this become possible?

 採用された回答

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019 年 12 月 7 日
編集済み: JESUS DAVID ARIZA ROYETH 2019 年 12 月 7 日

1 投票

m=input('z= ');
n=m+1;
x=zeros(n,1);
for i=1:n
x(i)=input(['x',num2str(i),'= ']);
end
x=repmat(x,1,n).^repmat((0:1:m),n,1)

3 件のコメント

Fahmy Shandy
Fahmy Shandy 2019 年 12 月 7 日
Thanks, but it displays error usiing ==> power Matrix dimensions must agree.
Error in ==> bla bla bla at xx x=repmat(x,1,n).^(0:1:m)
JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019 年 12 月 7 日
I edit the answer, try again please
Fahmy Shandy
Fahmy Shandy 2019 年 12 月 7 日
It works. Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2017a

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by