필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Max Behr
Max Behr 2019년 8월 4일
댓글: Max Behr 2019년 8월 4일
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!

채택된 답변

madhan ravi
madhan ravi 2019년 8월 4일
b=a(vector==1,:)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by