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,...)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 = […]

# Monthly Archives: December 2013

## 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'); endparfor 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 […]

## 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 foo1 = zeros(1,100); foo2 = cell(1,100); for i = 1:100 [tmpFoo1, tmpFoo2] = foo ( X ); foo1(i) = tmpFoo1; foo2{i} = tmpFoo2; end […]