MATLAB Answers

Calling an object's method that changes its property not doing what I want.

조회 수: 2(최근 30일)
Evan
Evan 16 Dec 2011
Hello
An object has property MNL_beta and method train(input, output) that I want the object to update its MNL_beta property. What is actually happening is :
>> p1
p1 =
predictor_bundle
Properties:
MNL_beta: []
Methods
>> p1.train(input, output)
ans =
predictor_bundle
Properties:
MNL_beta: [3x1 double]
Methods
>> p1
p1 =
predictor_bundle
Properties:
MNL_beta: []
Methods
What has happened? The p1's value has not changed at all?!?
>> p1 = p1.train(input, output)
p1 =
predictor_bundle
Properties:
MNL_beta: [3x1 double]
Methods
>> p1
p1 =
predictor_bundle
Properties:
MNL_beta: [3x1 double]
Methods
But using the second syntax, it's done what I wanted. How do I accomplish the result of the second method, while using the syntax of the first method?
Thank you

  댓글 수: 0

로그인 to comment.

채택된 답변

Chirag Gupta
Chirag Gupta 16 Dec 2011
This would stem from the difference between Value classes and handle classes. Its explained here: http://www.mathworks.com/help/techdoc/matlab_oop/brfylwk-1.html

  댓글 수: 1

Evan
Evan 16 Dec 2011
And so how would I exactly solve the problem?
My classdef is written as such :
classdef predictor_bundle
properties
MNL_beta
end
method
function obj = train(obj, input, output)
function here
end
end
end

로그인 to comment.

추가 답변(1개)

Evan
Evan 16 Dec 2011
Hello,
Here is my classdef code. What modifications would I need to make to solve the problem?
classdef predictor_bundle
properties
MNL_beta;
end
methods
function obj = predictor_bundle()
end
function obj = train(obj, input, output)
Function here.
end
end
end

  댓글 수: 2

Chirag Gupta
Chirag Gupta 16 Dec 2011
classdef predictor_bundle < handle
....
end
Chirag Gupta
Chirag Gupta 16 Dec 2011
http://www.mathworks.com/matlabcentral/answers/12056-matlab-oop-question

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by