Effacer les filtres
Effacer les filtres

Taking all values of a row if matrix fulfills vector=1

3 vues (au cours des 30 derniers jours)
Max Behr
Max Behr le 4 Août 2019
Commenté : Max Behr le 4 Août 2019
Hello,
I got a matrix and a vector like this:
>> a= rand(5)
>> a= rand(5)
a =
0.8147 0.0975 0.1576 0.1419 0.6557
0.9058 0.2785 0.9706 0.4218 0.0357
0.1270 0.5469 0.9572 0.9157 0.8491
0.9134 0.9575 0.4854 0.7922 0.9340
0.6324 0.9649 0.8003 0.9595 0.6787
vector=[1; 0;0; 1; 1]
vector =
1
0
0
1
1
If I write this, I will only get the values of the first colum.
b=a(vector==1)
b =
0.8147
0.9134
0.6324
But I would like to have the whole row instead of the values of the first colum. Like this:
b=
0.8147 0.0975 0.1576 0.1419 0.6557
0.9134 0.9575 0.4854 0.7922 0.9340
0.6324 0.9649 0.8003 0.9595 0.6787
Thanks!

Réponse acceptée

madhan ravi
madhan ravi le 4 Août 2019
b=a(vector==1,:)

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by