Similar to Binary search, I need a Decomposition method like it is described below.

1 次查看(过去 30 天)
I have an array 'x'. Eg:
x = 1:15;
The values in x is used from start to end by other function (function1) linearly. function2 returns logical value. Eg:
function flag = mainfunction(x)
for idx =1:length(x)
y = function1(x(idx));
if function2(y)
flag = false;
return
end
end
flag = true;
end
Instead of using the values of x from start to end (idx = 1:15 - linear), i need to use it as in binary search but with a difference (Other half should not be rejected). Like the image below,
Now, 'idx' should be in this flow, idx = [8,4,12,2,6,10,14,1,3,4,7,9,11,13,15] till it enters the inside if statement
Can anyone help me out?
Thanks in advance!

回答(1 个)

Naveen Venkata Krishnan
Hello,
If you want idx to follow a particular flow you can directly give it as follows
for idx = [8,4,12,2,6,10,14,1,3,4,7,9,11,13,15]
What does the "till it enters the inside if " means ? Is it like idx should change the flow after the flag becomes false ?

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by