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

1 visualizzazione (ultimi 30 giorni)
Mohamad Haj il 11 Dic 2021
Commentato: Mohamad Haj il 11 Dic 2021
the output is [1 1 1 1;2 4 8 16;3 9 27 81;4 16 64 256]
##### 2 CommentiMostra NessunoNascondi Nessuno
Walter Roberson il 11 Dic 2021
Modificato: Walter Roberson il 11 Dic 2021
Mohamad Haj il 11 Dic 2021
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

Accedi per commentare.

### Risposta accettata

Awais Saeed il 11 Dic 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 CommentiMostra 4 commenti meno recentiNascondi 4 commenti meno recenti
Awais Saeed il 11 Dic 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
Mohamad Haj il 11 Dic 2021
I will try it

Accedi per commentare.

### Categorie

Scopri di più su Matrix Indexing in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by