match with ismember function

2 ビュー (過去 30 日間)
Sourangsu Chowdhury
Sourangsu Chowdhury 2018 年 2 月 25 日
回答済み: Birdman 2018 年 2 月 25 日
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

採用された回答

Birdman
Birdman 2018 年 2 月 25 日
idx=setdiff(v,Mat(:,1)).';
idx=[idx zeros(numel(idx),1)];
res=sortrows([Mat;idx])

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by