Very Slow Assignment for Clas Properties
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi
I have a class with a number of properties. One of the methods for this class which uses these properties is called many times (530,553 times) as part of a sim i run.
Problem is referencing the properties takes up too much cumulative time.
For example I have:
classdef World < handle
properties state = 0;
end
methods
function thisWorld = World()
end
function act(thisWorld)
myState = thisWorld.state; % takes 15 seconds when called 503k end
Another method updates the state property prior to calling the act() method, the values 'state' can be assigned range from 1:1:101.
Please help end
end
0 Kommentare
Antworten (2)
Daniel Shub
am 6 Aug. 2011
This is a well known problem with MATLAB classes. Unfortunately there is not a good solution that I know of. I would suggest starting at:
0 Kommentare
Greg
am 15 Aug. 2011
1 Kommentar
Daniel Shub
am 15 Aug. 2011
It is a problem. Sometimes you can get around the problem by changing how your code works. For example:
N = 503e3;
thisWorld = World;
for ii = 1:N
myState = thisWorld.state;
end
is much faster than
for ii = 1:N
act(thisWorld);
end
obviously not all problems can be solved this way, but sometimes they can be.
Siehe auch
Kategorien
Mehr zu Performance and Memory finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!