Loop function in Matlab Programming
1 view (last 30 days)
Hello all, I am trying to make a loop as below description in Matlab programming. It likes two trees exploration.
I create a function with two input variables and output with four vars.
From originCoord(x,y) it creates two new coordinates R(x,y), L(x,y); (R means Right, L: left)
next R(x,y) -> new R1(x1,y1) & L1(x1,y1) and L(x,y) -> new L2(x2,y2) & R2(x2,y2)
then to be continued .....
loop will stop when one of the newCcoordinates() == targetCoordinates(xtarget, ytarget).
[R1,L1] = doRightRunning(x,y);
[L2,R2] = doLeftRunning(x,y);
[R3,L3] = doRightRunning(R1_x,R1_y);
[R4,L4] = doRightRunning(L1_x,L1_y);
[R5,L5] = doLeftRunning(R2_x,R2_y);
[R6,L6] = doLeftRunning(L2_x,L2_y);
I got stuck when the output always greater than input. I cannot use all the output for the next loop.
Please help me to comment on how to make a loop for this case. Thanks.
Problem2: when one of the newCcoordinates() == targetCoordinates(xtarget, ytarget), how can I know which varibales in which direction from origin loop to last loop generating the result? (like which brands of the tree achieving the target). In C++, I can use stack to save but in Matlab I do not know how can I save the variable for each loop.