i am running a loop in the first script, and in the second script there is loop generate random number "rN".
and there is a condition in the first script says:
if rN > 0.9
c=('stop')
end
how i can combine these two script ?????

7 件のコメント

James Tursa
James Tursa 2019 年 5 月 8 日
Please show your two scripts, or at least enough of a subset of them, to give us more detail.
gonzalo Mier
gonzalo Mier 2019 年 5 月 8 日
Always in this cases is a good practice to show a full example of what you are doing. Do you have any reason for not doing the second script a function that it's called by the first one? The function of the second script can return rN and do your math with that
mohammed alany
mohammed alany 2019 年 5 月 8 日
first scrript
%% animation part
while( distanceToGoal > goalRadius )
[v, omega] = step(controller, robot.CurrentPose);
drive(robot, v, omega)
robotCurrentLocation = robot.CurrentPose(1:2)
distanceToGoal = norm(robotCurrentLocation - robotGoal);
if rN > 0.9
c=('stop')
end
end
second script
for i = 1 : 5
rN = rand;
pause(2)
disp(['rN = ' num2str(rN)])
end
Walter Roberson
Walter Roberson 2019 年 5 月 8 日
%% animation part
while( distanceToGoal > goalRadius )
[v, omega] = step(controller, robot.CurrentPose);
drive(robot, v, omega)
robotCurrentLocation = robot.CurrentPose(1:2)
distanceToGoal = norm(robotCurrentLocation - robotGoal);
for i = 1 : 5
rN(i) = rand;
pause(2);
disp(['rN = ' num2str(rN)])
end
if any(rN > 0.9)
c = 'stop';
%did you want to break out of the while loop here?
end
end
mohammed alany
mohammed alany 2019 年 5 月 8 日
if the code below strat
for i = 1 : 5
rN(i) = rand;
pause(2);
disp(['rN = ' num2str(rN)])
end
the code below will stop working till finishing the loop
while( distanceToGoal > goalRadius )
Walter Roberson
Walter Roberson 2019 年 5 月 9 日
As rN values are generated, at what point should they become available to the other loop? As soon as possible after they are generated? After the 2 second pause? After the 'disp' ?
Should each iteration of the while loop be given the 5 random numbers, or should each iteration be given one random number? Should the 2 second pause affect the while loop?
mohammed alany
mohammed alany 2019 年 5 月 9 日
yas
1- rN values should they become available As soon as possible after they are generated?
2-while loop have to continue calculating till rN > 0.9, then (while loop have to stop to start another condition)

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2019 年 5 月 9 日

0 投票

%% animation part
while( distanceToGoal > goalRadius )
[v, omega] = step(controller, robot.CurrentPose);
drive(robot, v, omega)
robotCurrentLocation = robot.CurrentPose(1:2)
distanceToGoal = norm(robotCurrentLocation - robotGoal);
rN = rand;
disp(['rN = ' num2str(rN)])
if rN > 0.9
break;
end
pause(2);
end

2 件のコメント

Walter Roberson
Walter Roberson 2019 年 5 月 9 日
In this code, one rN value will be generated for each while loop iteration. This achieves your goal that the while loop continues calculating until an rN > 0.9 is generated.
mohammed alany
mohammed alany 2019 年 5 月 9 日
Many thanks dear

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by