From: Chris on 14 Mar 2010 20:18 I am trying to store a bunch of vectors which are returned from a function being used in a for loop. The function called 'function' will return a vector (of undetermined varying length) depending on the data fed into it (from Dataset). for i = 1:40 Results(i,:) = function(Dataset(i)); end The only way I've been able to make this sort-of-work so far is to turn the vector inside 'function' into a structure, and return the structure to be stored in Results(i). Is there an easier way to do this without having to modify 'function'?
From: Jan Simon on 14 Mar 2010 22:31 Dear Chris! > I am trying to store a bunch of vectors which are returned from a function being used in a for loop. The function called 'function' will return a vector (of undetermined varying length) depending on the data fed into it (from Dataset). You can use a cell: Results = cell(1, 40); for i = 1:40 Results{i} = fun(Dataset(i)); end BTW: "function" is no valid function name. Kind regards, Jan
From: James Tursa on 14 Mar 2010 22:39 "Chris " <haller(a)engr.orst.remove.this.edu> wrote in message <hnjubt$1ad$1(a)fred.mathworks.com>... > I am trying to store a bunch of vectors which are returned from a function being used in a for loop. The function called 'function' will return a vector (of undetermined varying length) depending on the data fed into it (from Dataset). > > for i = 1:40 > Results(i,:) = function(Dataset(i)); > end > > The only way I've been able to make this sort-of-work so far is to turn the vector inside 'function' into a structure, and return the structure to be stored in Results(i). Is there an easier way to do this without having to modify 'function'? You might consider a cell array. e.g., Results{140} = []; % pre-allocate for i = 1:40 Results{i} = function(Dataset(i)); end James Tursa
From: Jos (10584) on 15 Mar 2010 02:41 "Chris " <haller(a)engr.orst.remove.this.edu> wrote in message <hnjubt$1ad$1(a)fred.mathworks.com>... > I am trying to store a bunch of vectors which are returned from a function being used in a for loop. The function called 'function' will return a vector (of undetermined varying length) depending on the data fed into it (from Dataset). > > for i = 1:40 > Results(i,:) = function(Dataset(i)); > end > > The only way I've been able to make this sort-of-work so far is to turn the vector inside 'function' into a structure, and return the structure to be stored in Results(i). Is there an easier way to do this without having to modify 'function'? Besides using a cell array, you *can* use a structure without modifying the function you are calling: for i = 1:40 % as said before , % "function" is an invalid name ... Results(i).values = function(Dataset(i)); end hth Jos
|
Pages: 1 Prev: Power set of a set Next: ode and fminsearch function in the same file |