Using Multiple Classes/Files MATLAB
Hello,
I am having some trouble understanding object oriented progrraming in MATLAB.
I have created a script .m file which I want my general code to run in and produce the output(s) that I want.
I have also create three separate .m files, each of which contain three different classes, and these classes each have a constructor as well as a function which returns a public variable of the class which is initialized thru the constructor.
My goal is to create an instance of these three different classes in the script .m file as I earlier mentioned, as I want to access this public variable from each class in the main script file as it is needed to run my program/produce the output.
For reference, here is an example of the class I am talking about:
classdef className
properties
%general variables
%variable i want accessed the main script
end
methods
function r = className(%general variables)
%variable i want accessed=(math operation using general
%variables)
r=className
end
function randomName = randomName()
randomName=%variable i want accessed int he main script
end
end
endHello,
I am having some trouble understanding object oriented progrraming in MATLAB.
I have created a script .m file which I want my general code to run in and produce the output(s) that I want.
I have also create three separate .m files, each of which contain three different classes, and these classes each have a constructor as well as a function which returns a public variable of the class which is initialized thru the constructor.
My goal is to create an instance of these three different classes in the script .m file as I earlier mentioned, as I want to access this public variable from each class in the main script file as it is needed to run my program/produce the output.
For reference, here is an example of the class I am talking about:
classdef className
properties
%general variables
%variable i want accessed the main script
end
methods
function r = className(%general variables)
%variable i want accessed=(math operation using general
%variables)
r=className
end
function randomName = randomName()
randomName=%variable i want accessed int he main script
end
end
end Hello,
I am having some trouble understanding object oriented progrraming in MATLAB.
I have created a script .m file which I want my general code to run in and produce the output(s) that I want.
I have also create three separate .m files, each of which contain three different classes, and these classes each have a constructor as well as a function which returns a public variable of the class which is initialized thru the constructor.
My goal is to create an instance of these three different classes in the script .m file as I earlier mentioned, as I want to access this public variable from each class in the main script file as it is needed to run my program/produce the output.
For reference, here is an example of the class I am talking about:
classdef className
properties
%general variables
%variable i want accessed the main script
end
methods
function r = className(%general variables)
%variable i want accessed=(math operation using general
%variables)
r=className
end
function randomName = randomName()
randomName=%variable i want accessed int he main script
end
end
end class, function, matlab MATLAB Answers — New Questions