Uncategorized

Making function returns in Matlab compact


Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /data/1/b/1b32a628-bdcf-4151-86ff-5d5550106b39/nonconditional.com/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 380

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /data/1/b/1b32a628-bdcf-4151-86ff-5d5550106b39/nonconditional.com/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 380

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

Your email address will not be published. Required fields are marked *