Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Insert row in an array and delete last row
Replies: 7   Last Post: Jan 21, 2013 2:38 AM

 Messages: [ Previous | Next ]
 Michael Doukas Posts: 12 Registered: 12/26/12
Re: Insert row in an array and delete last row
Posted: Jan 21, 2013 2:38 AM

dpb <none@non.net> wrote in message <kdhfrn\$hft\$1@speranza.aioe.org>...
> On 1/20/2013 11:11 AM, Michael Doukas wrote:
> > "Michael Doukas" wrote in message
> > <kdh748\$a5g\$1@newscl01ah.mathworks.com>...

> >> I have the following code (it is for a Tabu search algorithm):
> >>
> >> 1: InitialSol=generator;

> 2: lsol=size(InitialSol,2);
> >> 3: List=zeros(l,lsol);
> >> 4: i=0;
> >> 5:

> 6: while i<=l
> >> 8: Sol=tweak(InitialSol);
> >> 9: % check if tweaked child already exists in the tabu list
> >> 10: if ismember(Sol,List)==0
> >> 12: List=circshift(List,1);

> 13: List(i,:)=Sol;
> >> 14: i=i+1;
> >> 15: end
> >> 16: end
> >> But it reaches line 13 and throws:
> >> Subscript indices must either be real positive integers or logicals.

> ...
>
> Quite a few problems here...
>
> The immediate problem is that you initialized i to zero and so the first
> time there's a new entry added the subscript for L(i,:) is L(0,:).
>
> Either initialize i=1; or move the increment to be before the first usage.
>
> But, the ismember() usage isn't right, anyway...remember the 'rows'
> optional argument? Plus, it returns a logical array which will be T iff
> each member is T. If the idea is to not have any duplicates in L, then
>
> if ~any(ismember(Sol,List,'rows')
>
> doc any
> doc equal
>
> --

Yes, in the meanwhile I figured it out on my own.
Thank you anyway for your great help.

Date Subject Author
1/20/13 Michael Doukas
1/20/13 dpb
1/20/13 Michael Doukas
1/20/13 dpb
1/20/13 Michael Doukas
1/20/13 Michael Doukas
1/20/13 dpb
1/21/13 Michael Doukas