Thursday, May 21, 2015

List all open files in matlab

There is a neat hack to print all the open matlab files in the editors.
This is useful for me when I have 12 tabs open, and would like to have a snapshot of files that I am packaging together.

http://undocumentedmatlab.com/blog/accessing-the-matlab-editor

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

Find and remove nan from matlab arrays

Sometimes the matrix has nans on the rows, and we would have to get rid of them before we could do any analysis.
A(any(isnan(A),2),:)=[];