From: Manthos Vogiatzoglou on 28 Feb 2010 06:47 Dear all I am having some problems using varargout.I red the documentation but it seems that I am missing something. This is my code: varargout = myfunc(theta, data, type) % if type = 1 the function should produce two output arguments, say v1 and v2 % while if type = 2 there are three outut arguments, v3, v4 and v5. My code is % something like that switch type case 1 calculate v1 and v2 case 2 calculate v3 v4 and v5 end switch type case 1 varargout(1) = v1; varargout(2) = v2; case 2 varargout(1) = v3; varargout(2) = v4; varargout(3) = v5 end %-------------------------------------------------------------------------------------- % end of code I run the following command [ out1 out2 out3] = myfunc(theta, data, 2) and I get the following error: ??? In an assingment A(I) = B the number of elements in B and I must be the same Can anyboby help me on this? Thanks in advance
From: Jan Simon on 28 Feb 2010 07:32 Dear Manthos! > I am having some problems using varargout.I red the documentation but it seems that I am missing something. This is my code: > > varargout = myfunc(theta, data, type) > ... > varargout(1) = v1; varargout(2) = v2; 1. You forgot the keyword "function" ? function varargout = myfunc(theta, data, type) 2. VARARGOUT is a cell, so the elements have to be accessed with curly braces: varargout{1} = v1; varargout{2} = v2; General advice: Use one command per line. VARARGOUT is slow, so avoid it whenever it is possible by e.g.: function [out1, out2] = Func(a,b,c) switch nargout case 2 out1 = v1; out2 = v2; case 1 out1 = v1; end Kind regards, Jan
|
Pages: 1 Prev: How can I solve a equation, which is mixing of ODE and PDE Next: cube drawing and rotation |