How to reconstruct 2 column array to m*n array which is contain logic function that defined whether it have that specific row in that 2 column array or not.

I want to transfer from 2 column array on the left hand side to m*n array like in the right hand side. The two array is the same meaning but I don't know how to transform it automatically because I have a lot of data that have to do this process.
Supposed from the left hand side it is array A and B respectively, I tried
isempty(A(A(2,1) == B(1,2) & A(2,2) == B(2,1)))
the result is 1 but it's only one result but I want all the array B how can I do it? any ideas?

 Respuesta aceptada

[a,~,ii] = unique(A(:,1));
[b,~,jj] = unique(A(:,2));
out = [nan,a(:)';b,accumarray([jj,ii],1)]

2 comentarios

thank you very much. but I didn't understand your code in the 3rd line that much but It's work. Thanks again.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by