How do i set class members by calling its own methods?
1 view (last 30 days)
Show older comments
I wanted to create a class where i can implement a class and set its members by calling its own methods.
This is the example class here:
classdef MANOVA1
%MANOVA1 calculate manova1
% This class perform ANOVA1 on dataset
properties (GetAccess = public)
g;
end
properties (Access = private)
data;
end
properties (Dependent)
Test_statistics;
p_value;
end
methods
function obj = MANOVA1(filename)
if nargin == 1
obj.setData(filename);
end
if isempty(obj.g)
obj.setg();
end
end
function setData(obj, filename)
obj.data = struct2cell(load(filename));
end
function setg(obj, data)
if (nargin == 1)
data = obj.data;
end
obj.g = length(data);
end
end
end
I was trying to call the class to the dataset: problem_5_1 exercise, by this following code:
obs = MANOVA('dataset_problem_5_1.mat')
disp(obs.g)
But when i run this code, the values are empty, because the members inside the class wouln't set when calling from class' own methods. I could do that with C++ and Python.
0 Comments
Answers (1)
Steven Lord
on 9 Oct 2022
By default, classes in MATLAB are value classes. See this documentation page for a discussion of the differences between value classes and handle classes. Also see this documentation page for a discussion of how classes in MATLAB behave differently from classes in other object-oriented languages.
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!