use object for interative loop
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tom Wright
am 16 Apr. 2014
Kommentiert: Sean de Wolski
am 16 Apr. 2014
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 Kommentare
Akzeptierte Antwort
Tom Wright
am 16 Apr. 2014
1 Kommentar
Sean de Wolski
am 16 Apr. 2014
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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Construct and Work with Object Arrays finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!