[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #63160] Iterating over objects in a for-loop
From: |
Nicholas Jankowski |
Subject: |
[Octave-bug-tracker] [bug #63160] Iterating over objects in a for-loop |
Date: |
Wed, 5 Oct 2022 11:46:11 -0400 (EDT) |
Update of bug #63160 (project octave):
Status: Need Info => Confirmed
_______________________________________________________
Follow-up Comment #4:
interesting. octave has always been able to iterate over a char array, since
that's handled the same as a numeric array:
>> for idx = "abcd", idx, endfor
idx = a
idx = b
idx = c
idx = d
similar for cell arrays, and structs. At first glance I was assuming this is
a unique feature of "new" string objects. But a quick test shows matlab can
iterate over other object types as well.
trying a generic class object:
classdef myclass
properties
prop;
end
methods
function obj = myclass(val)
obj.prop = val;
end
function val = myprop(obj)
val =[obj.prop];
end
end
end
you can step through the object array in matlab but not octave:
matlab 2022a:
a(1) = myclass(1);
a(2) = myclass(2);
for idx = a, idx, end
idx =
myclass with properties:
prop: 1
idx =
myclass with properties:
prop: 2
trying the same in octave 8.0.0 (hg id: 8b75954a4670)
>> for idx = a, idx, end
error: invalid type in for loop expression near line 1, column 1
based on the error message i don't think this is just related to bug #47755,
as octave still doesn't consistently handle classdef object arrays in the
first place.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?63160>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/