Nested Loop not working
Show older comments
The error I am getting is Error using make_nextRow (line 21) Not enough input arguments. but i've rechecked the code and I can't see anything that is wrong
here is the code, and I commented what each line is supposed to to
function rowfcn = make_nextRow(array, start_row)
%
% rowfcn = make_nextRow(array, start_row)
%
% Returns a function handle, rowfcn. When the function handle
% is firet called, it will return the row defined by start_row.
% Every call afterwards will return the next row below.
%
% If there are no more rows to return, an empty array, [], is returned.
%
% Inputs:
% array - A numerical MxN array
% start_row - An index (integer) that indicates
% which row to start returning values from
%
% Outputs:
% rowfcn - A handle to nextRow, which when alle
%
M = start_row;
rowfcn = @nextRow; %Return a handle to the NESTED function, nextRow()
end
function row = nextRow()
% Check if M is within size(array) and if it is greater than 0
if M <= array(size) && M > 0
row = array(M,:); % Get the M'th row from array and assign to row
M= M+ 1; % Increment M
else
row = [];
end
end
*this is the test case I used: *
scores = [20,90;13,56;3,67;10,78;2,54]
next_score = make_nextRow(scores,1)
next_score()
next_score()
next_score = make_nextRow(scores,4)
next_score()
next_score()
next_score()
these are the answers i'm supposed to get for my test case:
>> scores = [20,90;13,56;3,67; 10,78;2,54]
>>scores=
20 90 13 56 3 67 10 78 2 54
>> next_score = make_nextRow(scores,1)
next_score =
@make_nextRow/nextRow
>> next_score()
ans = 20 90
>> next_score()
ans = 13 56
>> next_score = make_nextRow(e7_scores,4)
next_score =
@make_nextRow/nextRow
>> next_score()
ans = 10 78
>> next_score()
ans = 2 54
>> next_score()
ans = []
Accepted Answer
More Answers (1)
Matt J
on 14 Oct 2012
At the command line, execute
which -all make_nextRow
and see if it reports any other versions of make_nextRow existing on your path.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!