필터 지우기
필터 지우기

How to "filter" a matrix using a vector quantity?

조회 수: 4 (최근 30일)
Shane
Shane 2014년 7월 2일
편집: Star Strider 2014년 7월 3일
I have a matrix [8x3] and a vector quantity that's [6x1].
What I'm trying to do is pick out the three values from the vector within the matrix. Here is the code I'm running.
x=[1;2;3;4;5;6]
x =
1
2
3
4
5
6
y=[1,2,3;2,2,3;3,3,4;4,5,7;5,6,7;6,7,8;7,4,3;8,2,3]
y =
1 2 3
2 2 3
3 3 4
4 5 7
5 6 7
6 7 8
7 4 3
8 2 3
N=y(x)
N =
1
2
3
4
5
6
Obviously my code has more numbers, but essentially the above is what I'm trying to do. However, I want to keep the entire matrix from rows 1 through 6 intact in the answer. Is there any command that can do that? In other words, I want this as the final answer:
N =
1 2 3
2 2 3
3 3 4
4 5 7
5 6 7
6 7 8
I just typed the last part in in, but how do I do that for bigger number sets with a certain command automatically? Thanks

채택된 답변

dpb
dpb 2014년 7월 3일
Almost there...
N=y(x,:);
the x vector is the row index, : picks up all the columns.
doc colon
for the details. Also might working thru the exercises/examples in the "Getting Started" section on basic array manipulation and addressing...

추가 답변 (1개)

Shane
Shane 2014년 7월 3일
That's makes sense.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by