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
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 ?

카테고리

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