match with ismember function
조회 수: 1 (최근 30일)
이전 댓글 표시
Suppose I have a matrix and a vector,
Mat= [1 343
3 655
4 565
7 676]
and a vector
v = [1 2 3 4 5 6 7];
I want output as
out [1 343
2 0
3 655
4 565
5 0
6 0
7 676]
I am trying to use
[~,idx] = ismember(v,(Mat(:,1)))
out = Mat(idx,:)
This doesnot work
댓글 수: 0
채택된 답변
Birdman
2018년 2월 25일
idx=setdiff(v,Mat(:,1)).';
idx=[idx zeros(numel(idx),1)];
res=sortrows([Mat;idx])
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!