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

1 vue (au cours des 30 derniers jours)
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!

Réponses (1)

Naveen Venkata Krishnan
Naveen Venkata Krishnan le 10 Oct 2019
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 ?

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by