Constructor not working, preallocating object leaves object with no properties
显示 更早的评论
function obj = ameth(t)
if nargin > 0
obj(numel(t)) = ameth;%preallocates the obj
for i=1:numel(t)
obj(i).trk = t(i);
end
end
end
This is under methods in my class definition, and is the constructor. trk is the only protected access property. When I call this method (h = ameth), I find that it returns an answer with no properties, but I am expecting to have the property trk. Where have I gone wrong?
采纳的回答
更多回答(1 个)
Are you sure it has no properties? If it is a protected property you have then you will not be able to see it when you display the object on command line, you will only see it inside the object (or inside an object of a derived class), e.g. in the breakpoint of a class function and even then it will not display in command window variables.
I often make my variables public while I am still working on developing a class just so I can see them easily, then I make them private or protected once I am satisfied things are working.
类别
在 帮助中心 和 File Exchange 中查找有关 Deploy to Java Applications Using MWArray Data API 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!