How do I pull data from two different matrices to form a new matrix?
Afficher commentaires plus anciens
Hi,
I have two different 30 x 10 matrixes (d1 and d2) that I am trying to pull rows from and only want a specific row from each of them to form a new matrix. The rows that I want are specified in another 30x1 matrix (I) with values of only 1's and 2's depicting the matrix I need to pull from.
I know i could pull one row of a specified matrix with the following command:
dtest=d1(I(1),:)
Unfortunately, I want to use my I matrix to select d1 or d2 in the above command.
Réponse acceptée
Plus de réponses (1)
Roger Stafford
le 20 Nov 2016
Modifié(e) : Roger Stafford
le 21 Nov 2016
p = repmat(I==1,1,10); <-- Corrected
D = p.*D1+(1-p).*D2; % <-- The desired result
2 commentaires
Walter Roberson
le 20 Nov 2016
I think your repmat() is off there; with a single count you are asking for repeating 10 horizontally and 10 vertically.
Roger Stafford
le 20 Nov 2016
Oops, you're right Walter. It should be
p = repmat(I==1,1,10);
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!