hello i need to write script mathlab to make a matrix with vector v=[1 2 3 4]

2 ビュー (過去 30 日間)
Mohamad  Haj
Mohamad Haj 2021 年 12 月 11 日
コメント済み: Mohamad Haj 2021 年 12 月 11 日
the output is [1 1 1 1;2 4 8 16;3 9 27 81;4 16 64 256]
  2 件のコメント
Mohamad  Haj
Mohamad Haj 2021 年 12 月 11 日
Thank you for help a=[1,2,3,4]; for i=2:4 a(i,:)=a((i-1),:).^2
end i do this code but there is an error in it and I don't know where

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

採用された回答

Awais Saeed
Awais Saeed 2021 年 12 月 11 日
Seems you want to have powers from 1 to 4
v = 1:4;
bsxfun(@power,v(:),[1:4]) % poers ranging from 1 to 4
ans = 4×4
1 1 1 1 2 4 8 16 3 9 27 81 4 16 64 256
  6 件のコメント
Awais Saeed
Awais Saeed 2021 年 12 月 11 日
  • Take transpose of vector a to make it a row vector.
  • Take square of a and put the result in second column
  • Take cube of a and put the result in third column.
  • Use index of for loop with .^ to take square, cube, etc
Mohamad  Haj
Mohamad Haj 2021 年 12 月 11 日
I will try it

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by