Writing "this" class' properties?
古いコメントを表示
Hi, I am new to Matlab classes. I want to change the value of some properties in a function called ChangeProperties from within the class. But I can't do it. What am I doing wrong?
classdef agent_type
properties
v
id
end
methods
function p=agent_type(i)
p.id=i;
p.v=10*randn(1,2);
end
function y=ChangeProperties(this,step)
[this.v(step,:)]=zeros(1,2);
y=[this.v(step,:)];
end
end
end
when I run: agent.ChangeProperties(2) I get a random 1x2 vector. It should be a zero 1x2 vector. Why does this.v remain the same?
Thank you
2 件のコメント
Andrew Newell
2011 年 3 月 23 日
I'm not sure what you're trying to do. Do you want to change your agent and also return a vector, or just change your object?
Andrew Newell
2011 年 3 月 23 日
Also, what is step supposed to do? As written, it is adding rows when step > 1.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Construct and Work with Object Arrays についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!