Thursday, May 7, 2015

List parsing in matlab

List parsing in matlab is not very trivial.
This is an example to find the members of A in B, and vice versa.

The matlab function, ismember does a nice job of set difference between two sets. However, I wanted to access both the elements (because I had data in other col to be matched).

Here is a simple example.

A = {'dog','cat','b','fish'};
B = {'fish','cat','a', 'horse','dog'};
[Lia,Locb] = ismember(A,B)
iA = find(Lia>0)
iB = Locb(Locb>0);

A(iA)
B(iB)

% iB = find(Locb>0)
for jj = 1:length(iA)
    iwantA = iA(jj)
    iwantB = iB(jj)
   
%     in python I could do for i in iA
    A(iwantA)
    B(iwantB)
    '=='
    pause
   
end

No comments: