Rank: 194358 based on 0 downloads (last 30 days) and 0 file submitted



Personal Profile:


Watch this Author's files


Comments and Ratings by Josh
Updated File Comments Rating
18 Apr 2013 Performance in object-oriented matlab code A very simple example to demonstrate an observation of mine regarding the use of classes in matlab. Author: Dimitrios Korkinof

There are two types of classes in MATLAB: value classes and handle classes.

When you call a member function of a value class, MATLAB copies the entire object into the member function space. This is why your code takes so long to run; each time you edit one element in the 400x400 array, MATLAB has to make a copy of the entire array.

If you use a handle class (put "< handle" at the end of the classdef line) then MATLAB only passes a pointer to the class to each member function. Thus, handle classes in MATLAB behave more like classes you're probably used to in other languages, and your code should run MUCH faster if you use a handle class.

Incidentally, you need to return a value from object class methods in order to modify the original object. Your modify_one function doesn't actually modify the c1 and c2 objects you define in PerfTest.m. If you were to examine the value of large_mat after the test code competes, it will still be all zeros.

Contact us