Taking all values of a row if matrix fulfills vector=1
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!