One of the object oriented programming (OOP) features in MATLAB is the ability to define classes, which can be used to facilitate encapsulation of data and operations. Classes are defined in MATLAB within a `classdef` block, followed by `properties`, `methods`, `events` and `enumeration` subblocks.
Questions tagged [matlab-class]
103 questions
1
vote
2 answers
Classdef and properties
For OO programming we use classdef in matlab.
Could someone explain to me how could I access the super class ? What is the role of properties, are they like constructors in Java?

lola
- 5,649
- 11
- 49
- 61
1
vote
2 answers
Can I call a classes method using str2func?
I am trying to use str2func to call different methods of my class depending on a specific properties value (in this case obj.type).
So, I have
classdef myClass
properties
type %# values are different file extensions (LSM, TIFF, OIF…

Azim J
- 8,260
- 7
- 38
- 61
1
vote
3 answers
MATLAB: How do I get the value of a class property given a property name
If I have a class defined as
classdef myclass
properties
foo = 3;
bar = 7;
end
end
And I want to access property foo I would write
obj = myclass()
obj.foo % Gives me 3
But, if I only have a string representation of the property name,…

Hannes Ovrén
- 21,229
- 9
- 65
- 75
1
vote
1 answer
Not able to work with properties in matlab class
The following MATLAB code does not work. I guess it has something to do that in the function changer, MATLAB tries to equal the objects A and B and not just setting the values to the same. Any workaround for that?
classdef foo
%FOO Summary of…

bios
- 997
- 3
- 11
- 20
1
vote
1 answer
Defining enumerations and constants locally in MATLAB
I would like to define enumerations and constants locally within the scope of a function.
I saw that MATLAB provides enumerations and constants as part of its object-oriented programming framework. However, if you try to define them within the scope…

Amelio Vazquez-Reina
- 91,494
- 132
- 359
- 564
1
vote
2 answers
Object array method dispatching
In MATLAB's new object model (classdef, etc): If I have an array of the object, and I call an ordinary method, is the methods called for each object, or for the entire array, i.e. is a single object passed into the method, or the entire array? I…

Marc
- 3,259
- 4
- 30
- 41
1
vote
3 answers
Define Multiple Enums in a Single File in Matlab
Is it possible to define multiple enumerations in a single Matlab file? Or is it possible to have "local" enums in the same way we can define local funtions at the end of a file?
I am working on a project where it would be handy to have multiple…

fishlein
- 145
- 1
- 8
1
vote
2 answers
How to make a member public in an class object created using MATLAB Class folder?
I'm trying to reuse a package in which all classes are written using Class folder i.e all methods are files inside a folder @myclassname. I would like to read the members of the class object. In normal classdef classes, declaring a property public…

Praveen
- 158
- 2
- 6
1
vote
1 answer
Matlab can't change parameters of a class while in constructor
I am calling a function to change parameters of my class inside its constructor, however, I can't change the values. Is this a bug or on purpose?
In the following example, I am calling function "calculateCalculatedProperties()" inside constructor.…

RedGermen
- 13
- 3
1
vote
1 answer
Read custom class in C application from MAT-file
I want to access the properties of a custom MATLAB class in a MAT-file in a C++ standalone application. The custom class is a class created in MATLAB with something like this:
classdef customClass
properties
myProp
end
methods
…

Tritium
- 23
- 3
1
vote
1 answer
MATLAB: How to make a property whose name is same as a keyword?
In this article (https://blogs.mathworks.com/loren/2012/07/16/who-what-why-but-not-this/) near the bottom Loren says that class properties can be the same as keywords. However, how is this possible? If you write a classdef script any attempt to use…

Giles Holland
- 11
- 1
1
vote
1 answer
Use a property of a classdef in another .m file?
Here is my code:
f.m:
classdef f < handle
properties (Access = public)
functionString = '';
x;
end
methods
function obj = f
if nargin == 0
syms s;
obj.x = input('Enter…

Eng.Fouad
- 115,165
- 71
- 313
- 417
1
vote
1 answer
Delete MATLAB subclass of graphics primitive
I'm trying to create a class similar to the Line object's class in MATLAB 2017b but having problem with the destructor. I want to achieve a similar behavior with other graphic objects that when deleted the handle is no longer referencing to that…

RudiRocker
- 33
- 5
1
vote
1 answer
matlab: copy handle class as value class
Is it possible to make Matlab to call a copy method of my class TMyClass (which is a handle calss) when an object of this class is assigned to a variable. In other words, I want my handle class to behave as a value class when copying it:
obj =…

Oleg
- 111
- 9
1
vote
2 answers
vectorization in matlab class
I have a class in MATLAB that represents an imaginary number. I have a constructor and two data members: real and imag. I am playing with overloading operator in a class and I want to make it work with matrices:
function obj = plus(o1, o2)
if…

Edwardo
- 643
- 3
- 9
- 23