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

조회 수: 1 (최근 30일)
the output is [1 1 1 1;2 4 8 16;3 9 27 81;4 16 64 256]

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by