필터 지우기
필터 지우기

extracting values and respective rows from a colummn

조회 수: 1 (최근 30일)
Sami
Sami 2011년 6월 6일
Hallo,
this is my problem:
I have a column B and a matrix A A contains in its first column the values of the B But A has a lot more values which I do not need. I want to create a code that extracts from the matrix A the rows corresponding to the values that are in the B column.
Hope that somebody can help,
Thanks in advance.
Sami

채택된 답변

Matt Fig
Matt Fig 2011년 6월 6일
I assume your A and B look something like this:
% Create some data to work with...
B = [3 5 7 9].';
A = round(rand(10)*100)/100;
A([2 10 4 7],1) = B % Put B in first column of A
To get the rows of A which have the values of B in the first column:
A_new = A(ismember(A(:,1),B),:)
  댓글 수: 2
Sami
Sami 2011년 6월 6일
thanks a lot !!! it works
Jan
Jan 2011년 6월 6일
+1: I *must* vote your answer: it is too obvious that it is the best answer in my opinion. :-)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by