Generating vector with certain element of matrix

조회 수: 1 (최근 30일)
Tanmoy
Tanmoy 2015년 5월 17일
댓글: Star Strider 2015년 5월 17일
Say, I have a matrix M = [ 4 5; 10 4; 4 7; 20 6; 4 8 ] I wanna create a vector with 4 (4's that exist only in 1st column) I can't consider 4's from 2nd column of the matrix. Answer will be : V = [4 5 7 8]
By find function, I get [4 5 ; 4 7; 4 8] but how to store them as [4 5 7 8] ?
Another question: side = find(M(1,:) == 4) gives me [4 5 ; 4 7; 4 8]. I have [4 5] already. So, I only want [4 7; 4 8] as output So, how to exclude [4 5] , or first row. I am trying to apply ~ . But, how?

채택된 답변

Star Strider
Star Strider 2015년 5월 17일
This works:
A = [ 4 5; 10 4; 4 7; 20 6; 4 8 ];
N = 4;
Result = [N; A(A(:,1)==N,2)]';
With those column constraints, it is possible to use ‘logical indexing’ to get the result.
  댓글 수: 2
Tanmoy
Tanmoy 2015년 5월 17일
Thank you so much.
Star Strider
Star Strider 2015년 5월 17일
My pleasure.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by