Same values in matrix column

Hello. I have the next problem.
I have the matrix and i want to create a new one who will give to the common values ​​of the first column all the values ​​of the second. For example . Can anyone help me about a command on this. Thanks in advance

 Respuesta aceptada

Voss
Voss el 19 de Ag. de 2022
Here is a way:
m = [1 2; 1 5; 1 8; 2 4; 2 5];
[mm,~,jj] = unique(m(:,1));
n = numel(mm);
result = [mm zeros(n,nnz(jj == mode(jj)))];
for ii = 1:n
idx = jj == ii;
result(ii,2:nnz(idx)+1) = m(idx,2);
end
disp(result);
1 2 5 8 2 4 5 0

2 comentarios

nick
nick el 20 de Ag. de 2022
thanks you Voss
Voss
Voss el 20 de Ag. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Ag. de 2022

Comentada:

el 20 de Ag. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by