How to solve this issue?Help me out?

1 回表示 (過去 30 日間)
Arun Badigannavar
Arun Badigannavar 2013 年 3 月 8 日
classdef CEntity
properties
RandNumb
end
methods
function obj = CEntity
InitArray12()
end
end
end
function InitArray12()
obj.RandNumb=randi(100)
end
How to send value which is calculated in the "InitArray12" function to "RandNumb" which is there in the properties
  3 件のコメント
Nath
Nath 2013 年 3 月 8 日
編集済み: Nath 2013 年 3 月 8 日
The function InitArray12 is outside the classdef so it doesnt know the instance. Change it to return your values, and assign them in the constructor
Cedric
Cedric 2013 年 3 月 8 日
Are you sure that you want InitArray outside of your class definition? If so, Nath answered above; otherwise, you'll want to do something like:
classdef CEntity
properties
RandNumb
end
methods
function obj = CEntity()
obj = obj.InitArray12() ;
end
function obj = InitArray12(obj)
obj.RandNumb = randi(100) ;
end
end
end

サインインしてコメントする。

採用された回答

per isakson
per isakson 2013 年 3 月 8 日
Or this way
>> ce = CEntity()
ce =
CEntity
Properties:
RandNumb: 92
Methods
>>
where
classdef CEntity < handle
properties
RandNumb
end
methods
function obj = CEntity
InitArray12();
end
function InitArray12( obj )
obj.RandNumb = randi( 100 );
end
end
end
Read the entry "Value or Handle Class — Which to Use" in the on-line help

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by