MATLAB: Please Help with Number Arrangement

arrangementnumbers

Good Day!
I am having a problem regarding arrangement of numbers.
I have a matrix of
[1 2;
2 3;
3 4;
3 5;
4 6;
6 7];
First, I want to find the end node. In this example, 5. Then 5 is connected to 3 and a process will be performed. After that, the program must go to 7 which is connected to 6 and 4. when the program detects that the number is 4 it will stop and another operation will be performed.
Please help me. Any tips will do.
Thanks
Regards Dhon Xean

Best Answer

Do you mean something like this?
prompt = 'What is your test value? \n';
TestNo=input(prompt); %Test No.
a=[1 2;
2 3;
3 4;
3 5;
4 6;
6 7];
b= a(:,2)==TestNo; %Location
c=a(b,1);
d= a(:,2)==c;
if d == zeros(size(d))
if c == 4;
msgbox('another program will start');
end
else
e= a(d,1);
if e == 4;
msgbox('another program will start');
end
end