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?

 채택된 답변

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

댓글 수: 2

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by