Taking all values of a row if matrix fulfills vector=1
조회 수: 3 (최근 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!