Borrar filtros
Borrar filtros

How do i set class members by calling its own methods?

2 visualizaciones (últimos 30 días)
Zain Ahmed
Zain Ahmed el 9 de Oct. de 2022
Respondida: Steven Lord el 9 de Oct. de 2022
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.

Respuestas (1)

Steven Lord
Steven Lord el 9 de Oct. de 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.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by