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),:)=[];

Tuesday, March 31, 2015

Split Granule name to find the match

I wanted the MODIS granule name from the long list of MYD35_L2. The year and daynum-hhmmss etc mattered so that I could do a pattern match.
This is an easy fix.
  [token, remain] = strsplit(scene5a{i}, 'MYD35_L2.A');
  modname = token{2};
  ahr = str2double(modname(9:10));
  amin = str2double(modname(11:12));
  mday = str2double(modname(5:7));
  year =  str2double(modname(1:4));
  obsday = yearday(year,mday);
  dofm = str2double(datestr(obsday,7));
  mth = str2double(datestr(obsday,5));
  MODobs(c) = datenum(year,mth,dofm,ahr,amin,0);

Thursday, March 26, 2015

/bin/bash^M: bad interpreter: No such file or directory

Was trying to write a shell script with if;then;fi loop. Kept getting the error message!!!
% A lesson learned: do not write unix file in windows :)

wget quit with memory exhausted

When doing simple 

wget -nc -i list.txt,

I got my wget quit with "memory exhausted" prompt. The download halted. 

I solved the issue by removing the .listing file and re-running the wget.