# how to combine to matrix with the same rows and different columns

3 visualizzazioni (ultimi 30 giorni)
Maryam Hamrahi il 23 Dic 2016
Commentato: Maryam Hamrahi il 23 Dic 2016
I have matrix A with n rows and three columns, matrix B with n rows and one column. For instance, matrix A and B could be as follows:
A= [1 4
3 6
4 7
1 3
5 2
7 9]
B=[1
2
2
3
2
5]
As you see, matrix A and B have the same number of rows. I would like to produce matrix C from matrix A, but only rows which are “2” in matrix B.
C=[3 6
4 7
5 2]
It would be appreciated if you could give me some ideas for solving this problem.
Thanks
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Walter Roberson il 23 Dic 2016
A= [1 4
3 6
4 7
1 3
5 2
7 9];
C = A(B == 2, :);
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Maryam Hamrahi il 23 Dic 2016
Thank you very much Walter Roberson.

Accedi per commentare.

### Categorie

Scopri di più su Logical in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by