Problems with your code:
- nextRow() is not properly defined as a nested function but rather as a subfunction. As a consequence the input arguments, array and start_row, are "lost".
- IMO: "M" is not an appropriate name for a row number.
- "array(size)" should be "size( array, 1 )"
- "nested loop" in the title is misleading
Your comments and programming style is good
I've modified the code (see below) and run
scores = [20,90;13,56;3,67;10,78;2,54];
next_score = make_nextRow( scores, 1 )
next_score()
next_score()
which returns
next_score =
@make_nextRow/nextRow
ans =
20 90
ans =
13 56
>>
where
function rowfcn = make_nextRow( array, start_row )
M = start_row;
rowfcn = @nextRow;
function row = nextRow()
if M <= size( array, 1 ) && M > 0
row = array( M, : );
M= M+ 1;
else
row = [];
end
end
end
.
I don't know if that is the expected result. I let you check that.
Best Answer