Borrar filtros
Borrar filtros

match with ismember function

1 visualización (últimos 30 días)
Sourangsu Chowdhury
Sourangsu Chowdhury el 25 de Feb. de 2018
Respondida: Birdman el 25 de Feb. de 2018
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

Respuesta aceptada

Birdman
Birdman el 25 de Feb. de 2018
idx=setdiff(v,Mat(:,1)).';
idx=[idx zeros(numel(idx),1)];
res=sortrows([Mat;idx])

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by