use object for interative loop
조회 수: 2 (최근 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!