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

 Réponse acceptée

Tom Wright
Tom Wright le 16 Avr 2014

0 votes

I guess I can answer this myself now
while myobj.index < myobj.length
[myobj, newthing] = myobj.getNext(myobj)
%do thing with newthing
end

1 commentaire

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);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by