Taking all values of a row if matrix fulfills vector=1
1 view (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!