Giving a condition in for loop
1 次查看(过去 30 天)
显示 更早的评论
Let the initial values p (i) = false; i = 1: 10 and I have a condition say a <= b
What I want is:
1) I will run a loop for i = 1:10.
2) Then I want to know for which i the condition a<= b gets satisfied.
3) Then I want to make all the p's other than the index for condition was satisfied, to be true.
For example: if for i = 2 a<= b gets satisfied then I want to make p(1), p(3), p(4),......p(10) TRUE.
Can anyone give a code for this. Thanks
2 个评论
采纳的回答
Dyuman Joshi
2023-2-10
p=zeros(1,10);
b=0.5;
for idx=1:10
a=hypot(x(idx)-x_o,y(idx)-y>o);
if a<=b
p(setdiff(1:10,idx))=1;
end
end
Another method -
for idx=1:10
a=hypot(x(idx)-x_o,y(idx)-y>o);
if a<=b
p=ones(1,10);
p(idx)=0;
end
end
更多回答(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!