Reshape matrix to have the same value every 30 cells

조회 수: 1 (최근 30일)
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2018년 2월 19일
댓글: Jos (10584) 2018년 2월 19일
Hi All,
I have a question: I have a matrix
A=[10; 20; 30; 40; 50; 50; 60]
How can I reshape it in order to have a matrix (7x30) X 1 such that the first 30 values are A(1), the next 30 have value of A(2), and so on...
thanks
nikolas

채택된 답변

Guillaume
Guillaume 2018년 2월 19일
This is not a reshape it's a repmat:
repmat(A, 1, 30)
  댓글 수: 1
Jos (10584)
Jos (10584) 2018년 2월 19일
Just to be nitpicking :D ... the first 30 values of A, retrieved by A(1:30) will be [10 20 30 40 50 60 70 10 20 ...] because A is a column vector and Matlab stores values columnwise.

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

추가 답변 (1개)

Birdman
Birdman 2018년 2월 19일
편집: Birdman 2018년 2월 19일
B=mat2cell(repmat(A,1,30),ones(1,7),30)
type A{1} and the result will be 30 10's.
  댓글 수: 2
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2018년 2월 19일
Thanks for the reply however I am getting an error "Inner matrix dimensions must agree"
Guillaume
Guillaume 2018년 2월 19일
You're on a version earlier than R2016b. You have to use bsxfun on earlier versions.
Not that it matters, since the answer has completely changed.

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

카테고리

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