フィルターのクリア

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

2 ビュー (過去 30 日間)
Zain Ahmed
Zain Ahmed 2022 年 10 月 9 日
回答済み: Steven Lord 2022 年 10 月 9 日
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.

回答 (1 件)

Steven Lord
Steven Lord 2022 年 10 月 9 日
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.

カテゴリ

Help Center および File ExchangeRepeated Measures and MANOVA についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by