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

1 ビュー (過去 30 日間)
Prasanna Venkatesh 2019 年 8 月 29 日

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?

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

### 回答 (1 件)

Naveen Venkata Krishnan 2019 年 10 月 10 日
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 ?

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

### Community Treasure Hunt

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

Start Hunting!

Translated by