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
0
votes
0 answers
Add dynamicprops with a getter that doesn't engage on construction of object
I want to create a class that lets me load data only when a channel is requested.
I want it to work something like this:
my_file = Datafile('big_and_slow_file.dat');
ch1 = my_file.Channel_1;
ch102 = my_file.Channel_102;
In this case the file…

danneedebro
- 57
- 8
0
votes
1 answer
Defining a list of class instances in MATLAB
I am going to define a class in MATLAB called "Node" which is supposed to be a node of a tree structure.
I have a variable inside it called "NodeList" which is supposed to be a list of sub nodes.
Here is what I have defined:
classdef…

RDS
- 9
- 5
0
votes
1 answer
How to access property from static method
As the title says I am setting a property with the constructor and would like to access the property later as a get function that is static. How would I do this in MATLAB?
classdef Wrapper
properties(Access=public)
dataStruct
…

Steven
- 139
- 1
- 9
0
votes
0 answers
Abstract function working in command line, not working in class as constant property
Following function works at the command line, however not in the class as a constant property. I tried a lot of different combination with integral other function etc. but I was unable to solve it.
Function
enthalpyChange = @(constants,…

RedGermen
- 13
- 3
0
votes
0 answers
Weird error while using constant properties in class
I am trying to save functions as variables inside a class so I can reach them in an ordered manner. However, whenever I try to pull any constant from the following class, I get the following error.
%FORMULAS Summary of this class goes here
%…

RedGermen
- 13
- 3
0
votes
2 answers
Why isn't this object destroyed when it is cleared from the workspace?
I am working on a MATLAB class which stores an interface object created with tcpip and includes a callback function for the interface object to use, as per the following example:
classdef wsg50_mini2 < handle
properties
TCPIP
end
…

MaKaNu
- 762
- 8
- 25
0
votes
1 answer
Methods of Matlab's Built-in Objects
What are the differences between these two calling sequences get(a) and a.get()?
load gong
a = audioplayer(y, Fs);
a.get
get(a)

sci9
- 700
- 1
- 7
- 21
0
votes
1 answer
Difference between "OOP" and "functional" method invocation syntax
On this page that explains the use of inputParser class,
we see that every inputParser method call in the examples is of the form
methodname(object, arguments)
instead of
object.methodname(arguments)
For…

Hennadii Madan
- 1,573
- 1
- 14
- 30
0
votes
1 answer
Matlab class dynamic filling of a property
I'm trying to dynamically fill a property in a Matlab class.
I pass vectors to a method function and then compute various parameters. I would like to fill the properties in a for loop, see code example. The OwnClassFunction is just an example of a…

Prof. Putzmichel
- 3
- 2
0
votes
1 answer
Convert a class to structure and store in a .mat file - MATLAB
I have a class which has some properties that they are objects of other classes, when I convert the class to a struct and check the data, the full information of all properties exist. but after storing it to a .mat file, when I load the data, the…

Someone
- 163
- 1
- 3
- 13
0
votes
0 answers
Retain interactivity in Simulink sheet called from an object method
Let's say I have a simulation set up in Simulink, which consists of three blocks: Input (From Workspace block), model calculation (S-function block) and results (Outport).
In my class, I do a lot of preprocessing on the input data, which is not…

winkmal
- 622
- 1
- 6
- 16
0
votes
0 answers
Matlab "value" class not working properly
I've done a simple Matlab class
classdef WavReader
...
and I am trying to use it:
wr = WavReader(in_path);
wr.SetChunkLength( block_size);
while true
out = wr.ReadChunk();
However, this doesn't work: some class properties are "forgotten"…

Danijel
- 8,198
- 18
- 69
- 133
0
votes
1 answer
How to pass a structure or a class object to functions by reference in Matlab
I have several large matrices that should be passed to different functions many times in an iterative algorithm. How can I avoid the unnecessary copy of variables to the function to speed up the program? Is there any way to group these matrices in a…

Eman
- 165
- 1
- 1
- 8
0
votes
1 answer
Dependent properties of Matlab class that can store values using setters
Matlab class properties have the following two limitations which are relevant to my problem,
Dependent properties cannot store values
setter for Properties (normal properties with no specified attributes, access specifiers, etc) cannot access other…

Naveen
- 458
- 1
- 10
- 29
0
votes
1 answer
Making the fields of a struct property as properties of the class in Matlab
I need to define a class called MobileBaseStation and a property called DataChannel which is a struct as shown below,
classdef MobileBaseStation
properties
DataChannel = struct('TxScheme','SpatialMux','NLayers',4);
end
properties (Constant =…

Naveen
- 458
- 1
- 10
- 29