Reputation: 291
the program is working perfectly but when i am changing it to function the follwing error is beeing displayed:
[Parent1index, Parent1Position, alldcel] = Parent1n(TotalnoOfGrids, noOfNodes, Penalties, test)
??? Index exceeds matrix dimensions.
Error in ==> Parent1n at 10
[~,index]=min(alldcel{t});
Upvotes: 0
Views: 83
Reputation: 291
ok with this code the functiion worked:if Penalties{t}(r)> 0;
alldcel {t}(r)=alldcel{t}(r);
else alldcel {t}(r)=inf;
but interchanging if statement with else did not
Upvotes: 0
Reputation:
Because alldcell{t}
may not exist for some values of t
if the condition to assign values to it in
if Penalties{t}(r)== 0;
alldcel{t}(r)=inf;
end
is never satisfied. Assume for some t
that all values of Penalties{t}
are different than zero. Then you would never assign inf
to alldcell{t}
. That means, you are only extending the cell array alldcell
when Penalties{t}
is zero for some r
. If the condition is never satisfied, alldcell{t}
will not exist and asking for it will give you a cell array error.
You should at least initialize it using alldcell = cell(TotalnoOfGrids,1)
.
Also, comparing for equality to zero using a==0
is not a good idea. You should use abs(a)<tol
for some small value tol
.
Upvotes: 1