필터 지우기
필터 지우기

HOW CAN CREATE A MATRIX FROM A SINGLE ROW?

조회 수: 1 (최근 30일)
simone zappalà
simone zappalà 2022년 3월 13일
댓글: John D'Errico 2022년 3월 13일
I have 12 elements distributed on a single row, i've to put them on a 3x4 matrix, how i do that?

채택된 답변

Arif Hoq
Arif Hoq 2022년 3월 13일
use reshape function.
A=randi(100,1,12)
A = 1×12
99 27 87 54 85 99 10 14 94 9 80 42
output=reshape(A,3,4)
output = 3×4
99 54 10 9 27 85 14 80 87 99 94 42
  댓글 수: 1
John D'Errico
John D'Errico 2022년 3월 13일
With only the caveat that the solution offerd by @Arif Hoq puts the elements into the matrix going down the columns. If @simone zappalà wanted to put the elements going across rows from the original vector, then this subtle change would do the trick:
A = [99 27 87 54 85 99 10 14 94 9 80 42];
output=reshape(A,4,3).'
output = 3×4
99 27 87 54 85 99 10 14 94 9 80 42

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by