Reshape matrix to have the same value every 30 cells

1 visualización (últimos 30 días)
Nikolas Spiliopoulos
Nikolas Spiliopoulos el 19 de Feb. de 2018
Comentada: Jos (10584) el 19 de Feb. de 2018
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

Respuesta aceptada

Guillaume
Guillaume el 19 de Feb. de 2018
This is not a reshape it's a repmat:
repmat(A, 1, 30)
  1 comentario
Jos (10584)
Jos (10584) el 19 de Feb. de 2018
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.

Iniciar sesión para comentar.

Más respuestas (1)

Birdman
Birdman el 19 de Feb. de 2018
Editada: Birdman el 19 de Feb. de 2018
B=mat2cell(repmat(A,1,30),ones(1,7),30)
type A{1} and the result will be 30 10's.
  2 comentarios
Nikolas Spiliopoulos
Nikolas Spiliopoulos el 19 de Feb. de 2018
Thanks for the reply however I am getting an error "Inner matrix dimensions must agree"
Guillaume
Guillaume el 19 de Feb. de 2018
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by