How to use result in each iteration in a for loop and then use it in next loop?
1 次查看(过去 30 天)
显示 更早的评论
how can i use the result of the first iteration in other For loop?
3 个评论
Prasanth Sikakollu
2019-6-12
You can merge both the loops and use the result in the same iteration
for i=1:10
x = 10*i; % This is the value generated
y = x + 1; % Using generated value x to evaluate y
end
回答(2 个)
KSSV
2019-6-12
for i = 1:10
a = rand+rand ; % this is the result in first loop
for j = 1:3
b = a+rand ; % result of first loop used in second loop
end
end
0 个评论
Prasanth Sikakollu
2019-6-12
Merge both the loops and use the generated result in the same loop.
for i=1:10
x = 10*i; % This is the value generated. Expression on the RHS is a random one
y = x + 1; % Using generated value x to evaluate y
end
Hope this helps
0 个评论
另请参阅
类别
在 Help Center 和 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!