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 );
  end

Which makes sense and doesn't make sense.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>