Monthly Archives: December 2013


Chaining function calls in Matlab

Matlab has a nice feature that lets you chain commands by treating functions as variables. This means that you can write: a = "foo"; b = feval(a,arg1,arg2,...) Now if we want to chain commands acting on the same input we can write: myfoos = cell{'foo1','foo2','foo3',...}; x = ... chainedFoosOnX = applyChain(x,operators);   function x = […]

Saving from inside a parfor loop in Matlab

If you call save from a parfor loop in Matlab, like this for example: parfor k=1:100 foo = exp(-k); save(['myfile',num2str(k),'.mat'],'foo'); end it will generate an error. I have not exactly figured out why this is but probably it has to do with the fluctuating nature of the foo variable inside the parfor loop. By calling […]

Making function returns in Matlab compact

I used to write this in Matlab: foo1 = zeros(1,100); foo2 = cell(1,100); for i = 1:100 [tmpFoo1, tmpFoo2] = foo ( X ); foo1(i) = tmpFoo1; foo2{i} = tmpFoo2; end This was until I realized you can write: foo1 = zeros(1,100); foo2 = cell(1,100); for i = 1:100 [foo1(i), foo2{i}] = foo ( X […]