Prev: Cftool
Next: Recession bars in plot
From: Adam Hartshorne on 15 Feb 2010 18:19 Just wondering if it is possible to do the following in a single line, Say I have an array of Object A's lets call the array O, and each object has a parameter x... Now I have another array "update_x" (of the same size), which contains all the values which I want to set the values of O.x's to. so I want to do a single line O(i).x = x(i) I assumed it is something O(:).x = update_x(:), but that isn't the correct answer. Any help much appreciated.
From: Matt J on 15 Feb 2010 19:19 "Adam Hartshorne" <adam.hartshorne(a)gmail.com> wrote in message <hlckp7$f6u$1(a)fred.mathworks.com>... > Just wondering if it is possible to do the following in a single line, > > Say I have an array of Object A's lets call the array O, and each object has a parameter x... > > Now I have another array "update_x" (of the same size), which contains all the values which I want to set the values of O.x's to. > > so I want to do a single line O(i).x = x(i) > > I assumed it is something O(:).x = update_x(:), but that isn't the correct answer. > If update_x where a CELL array, you could do it like this [O.x]=update_x{:} or if you have an older version of MATLAB [O.x]=deal(update_x{:}) If you're stuck with update_x not being a cell array, you should really invest in making the following function one of your permanent utilities function varargout=dealcell(X) varargout=num2cell(X); end Then you can do something virtually the same as above [O.x]=dealcell(update_x)
|
Pages: 1 Prev: Cftool Next: Recession bars in plot |