How to reshape and repeat at the same time.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Bahaa Algebory
le 2 Jan 2017
Commenté : Bahaa Algebory
le 5 Jan 2017
Hi guys, I have the following data
data= [1 3 7 9 2 5]
and I want the data to be as a matrix (2*6)
newdata=1 1 7 7 2 2
3 3 9 9 5 5
Please help me, and thanks in advance.
0 commentaires
Réponse acceptée
Walter Roberson
le 2 Jan 2017
num_rows = 2;
num_copies = 2;
new_data = kron(reshape(data, num_rows, []), ones(1, num_copies));
Or less verbosely,
new_data = kron(reshape(data,2,[]),ones(1,2));
5 commentaires
Walter Roberson
le 5 Jan 2017
finaldata = reshape( permute(reshape(new_data, 2, 2, []), [2 1 3]), 1, [] );
Plus de réponses (1)
Roger Stafford
le 2 Jan 2017
newdata = reshape(repmat(reshape(data,2,[]),2,1),2,[]);
3 commentaires
Roger Stafford
le 5 Jan 2017
It is much easier to get ‘finaldata’ directly from ‘data’:
finaldata = reshape(repmat(data,2,1),1,[]);
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!