Prev: suppose I have an equation x^2+x+y^2+3*y=5*y^2+3*y+3*x*y+5 andI want to find the set of (x,y) that satisfy the equation.
Next: IEEE 14 bus coding
From: Richard on 12 Aug 2010 10:43 Hi, is it possible to vectorise computations on arrays of user defined objects? for example, I have an array of myObject that contains 400 myObject elements. I can access individuals using myObject(i). I'm using for i=1:length(myObject) myObject(i).property=myObject(i).property^2; end wouldn't it be much faster if I could do myObject(:).property=myObject(:).property^2; Can this be done? Is my problem with syntax ?
From: Matt J on 12 Aug 2010 10:53 "Richard " <REMOVETHISrcaldwellie(a)yahoo.com> wrote in message <i4119r$m2q$1(a)fred.mathworks.com>... > wouldn't it be much faster if I could do > > myObject(:).property=myObject(:).property^2; ================= Probably not. You have such a short for-loop that it's hard to improve upon. You can condense the operation to 1 statement using arrayfun myObject=arrayfun(@(ob) set(ob,'property',ob.property.^2),myObject) but it probably won't be faster.
From: Matt J on 12 Aug 2010 11:01
"Richard " <REMOVETHISrcaldwellie(a)yahoo.com> wrote in message <i4119r$m2q$1(a)fred.mathworks.com>... > wouldn't it be much faster if I could do > > myObject(:).property=myObject(:).property^2; > > Can this be done? Is my problem with syntax ? ================ The better thing to do would be to have a single myObject, instead of an array of them and store the property values as a vector in myObject.property. Then you could just do this myObject.property=myObject.property.^2; |