Note that there are some explanatory texts on larger screens.

plurals
  1. POMATLAB: Ignoring Specific Columns in a Matrix when Carrying Out a Loop
    primarykey
    data
    text
    <p>so far I have this:</p> <pre><code>for l=1:50 %# matrix of distances between terminal nodes, index of column represents %# where the searcher is going from and the index of the row represents %# where the searcher is going to d = [ 10 2 2 3 3 2 4 5 5 4 4 4 3 3 4 4; 10 10 2 5 5 4 6 7 7 6 6 6 5 5 6 6; 10 2 10 5 5 4 6 7 7 6 6 6 5 5 6 6; 10 5 5 10 2 3 7 8 8 7 7 7 6 6 7 7; 10 5 5 2 10 3 7 8 8 7 7 7 6 6 7 7; 10 4 4 3 3 10 6 7 7 6 6 6 5 5 6 6; 10 6 6 7 7 6 10 3 3 2 4 4 5 5 6 6; 10 7 7 8 8 7 3 10 2 3 5 5 6 6 7 7; 10 7 7 8 8 7 3 2 10 3 5 5 6 6 7 7; 10 6 6 7 7 6 2 3 3 10 4 4 5 5 6 6; 10 6 6 7 7 6 4 5 5 4 10 2 5 5 6 6; 10 6 6 7 7 6 4 5 5 4 2 10 5 5 6 6; 10 5 5 6 6 5 5 6 6 5 5 5 10 2 3 3; 10 5 5 6 6 5 5 6 6 5 5 5 2 10 3 3; 10 6 6 7 7 6 6 7 7 6 6 6 3 3 10 2; 10 6 6 7 7 6 6 7 7 6 6 6 3 3 2 10 ]; i=1; %# start the searcher at the origin h=5; t=0; %# start time of the game k=find(d(i,:)==min(d(i,:))); %# position closest nodes j=randsample(k,1,true); %# randomly selects closest node if multiple nodes within closest distance c=min(d(i,:)); while j~=h %# while the searcher is not in the same position as the hider d(:,j)=[]; %# delete the column corresponding to the searchers position so he cannot return here %# want to ignore all previous positions not delete them! i=j; %# reset the searchers current position k=find(d(i,:)==min(d(i,:))) %# find the new minimum distance p=rand(1)*length(k); %# randomly select an index of k q=floor(p)+1 %# take the integer part of k j=k(q) %# randomly select from all the closest nodes t=t+min(d(i,:))+c; %# calculate cumulative time for paths traveled end Found(l)=j-1 %# show position where the hider was found (relate matrix index to node index) Time(l)=t %# show time taken for the searcher to find the hider end </code></pre> <p>So the elements in <code>d</code> are the distance between two positions, represented by the row and column position, then the aim is to reach column 5 (<code>h</code>) by traveling the shortest distances between positions.</p> <p>The problem I have is that I am currently deleting each column as it is searched for the minimum distance, this is then redefining the index of the column and so when <code>h</code> is either not being reached or it is not the correct <code>h</code>. How can I ignore rows already searched in the 'while' loop?</p> <p>Any help will be gratefully received, thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload