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

2 Ansichten (letzte 30 Tage)
the output is [1 1 1 1;2 4 8 16;3 9 27 81;4 16 64 256]

Akzeptierte Antwort

Awais Saeed
Awais Saeed am 11 Dez. 2021
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 Kommentare
Awais Saeed
Awais Saeed am 11 Dez. 2021
  • 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by