Generating vector with certain element of matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!