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
undefined function or variable in class
How to output class property so that it can be accessed in MATLAB's terminal? In my case, ClassA stores p array and shows output like:
ClassA with properties:
p: [3x3 double]
But when I want to access the array, its always says undefined…
user3396151
1
vote
1 answer
Cannot iterate through cell array of strings which is constant property of a class
I am having trouble iterating through a cell array of strings which is a constant property in a class. Every time I try to index the cell array from 1 to end, Matlab crashes. What could I be doing wrong?
Code looks like this:
classdef classA
…

DEEPMALA
- 53
- 1
- 1
- 7
1
vote
1 answer
How much overhead is created by the oop paradigm in matlab
In matlab every class method seems like an ordinary method whose first argument is the object itself.
Such a paradigm is quite acceptable for other oop languages such as python, for the classes are passed by reference. On the other hand, matlab, by…

tantuni
- 671
- 1
- 8
- 19
1
vote
2 answers
Object not persisting
In the following piece of code, the destructor of class TdcTestResult is called at the end of function add, and so method variable mTdcTestResults will become empty again.
How can I make the instance of TdcTestResult inside mTdcTestResults…

Andre K
- 185
- 1
- 10
1
vote
1 answer
Use set method MATLAB
I want to change the value of a property in a Matlab class from a function within the same matlab class. I.e on of the functions in the class is generating a value that I want to assign to a property for that class.
This is the properties of the…

user3004700
- 31
- 3
1
vote
1 answer
Translating GPIB in MATLAB to PyVISA
I've inherited some MATLAB code used to program an XYZ stage through a GPIB connection. To make it more compatible with some existing code in Python, I need to somehow translate it, e.g. using the PyVISA package. I would really like some help with…

Happy
- 429
- 3
- 7
- 18
1
vote
1 answer
invoking superclass constructor
I read this documentation page about how to invoke superclass constructor from a child class. The syntax they mention is this:
obj = obj@MySuperClass(SuperClassArguments);
I'm wondering what the purpose of @ symbol in the above syntax is. Is the @…

user2166888
- 579
- 1
- 5
- 13
1
vote
1 answer
create array of objects of a class in another class MATLAB
I am trying to create an array of objects of a class Cell in another class Systemin MATLAB. The classCell` is:
classdef Cell
properties
ID;
EntityID;
ZoneID;
NeighborID;
State;
nextChangeTime;
end
methods
% Define the…

Nitin
- 2,624
- 7
- 29
- 43
1
vote
1 answer
missing value or empty string in enum
Is there a way to have an enum like this:
classdef(Enumeration) bla_type < int32
enumeration
bla_one(1)
bla_2(2)
end
end
with a missing or NaN value? Thanks.

cs0815
- 16,751
- 45
- 136
- 299
1
vote
1 answer
MATLAB class for loading files
Beginner with MATLAB here. I'm trying to write a class that will load in images from a folder, and here's what I have:
classdef ImageLoader
%IMAGELOADER Summary of this class goes here
% Detailed explanation goes here
properties
…

Eamonn McEvoy
- 8,876
- 14
- 53
- 83
1
vote
1 answer
calling setter with an extra argument? - MATLAB
In a class with the dependent property c, I would like to call c's setter with a third argument that equals 'a' or 'b', choosing which independent property to alter in order to set c.
The code is
classdef test < handle
properties
a
…

user1361521
- 87
- 1
- 1
- 4
1
vote
1 answer
Matlab property that automatically updates
Being new to MATLAB, I am trying to write a class where, if one of two properties changes value, a third property is automatically recalculated.
It seems events and listeners are made for this, but I just can't get the hang of their basic…

user1361521
- 87
- 1
- 1
- 4
0
votes
1 answer
Is there a good way here to allow users to both retain access control for properties and overload indexing methods?(matlab 2020a)
Assuming a member within a class has private access properties, i.e., GetAccess=private, if we use a "." type reference for that member in the overloaded subsref method, then the access property of that member becomes invalid at that…

bokabokaboka
- 69
- 5
0
votes
2 answers
How to overload A{n} in a custom class? matlab 2020a
Background knowledge
subsref
Some explanations in the book (published in 2014):
When overloading the subsref method, you can use a switch statement to select the type of index and obtain the actual index value. The following three code snippets…

bokabokaboka
- 69
- 5
0
votes
0 answers
(First time using MATLAB) Examples for constructors of htensor
Unfortunately, I have no experience with Matlab and now I need a few visualizations in this program.
At the moment i'm working on tensors and their approximation possibilities.
More specifically with this…

AsaMitaka
- 1
- 1