use object for interative loop
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have an object that I want to iterate through it's members with a while loop but I can't see how to call the while loop? Thanks, tom
classdef cls_myobj
properties
members = {'abc' 'bbc' 'cbc'}
length = 3
index = 0
end
methods
function [this,obj] = getNext(this)
this.index = this.index +1;
if this.index > this.length
obj = -1; %or false???
else
obj = this.members(this.index);
end
end
end
myobj=cls_myobj;
while [this, x] = getNext(myobj)
%do stuff
end
0 个评论
采纳的回答
Tom Wright
2014-4-16
1 个评论
Sean de Wolski
2014-4-16
It doesn't look right that you have myobj.method and method(myobj). I'd expected you'd only need one or the othr
[myobj,newthing] = getNext(myobj);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 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!