Exponential and Binary Search Algorithm

Hello, So I tried to convert a cpp program that uses exponential search and binary search. I am however getting errors within the code for MATLAB, I do not understand where I have gone wrong.
I have a main file here: PasteBin Main
Here is the function for exponential search: expo search function
This is the binary search: binary search
The errors I am getting are in the binary search function at line 4, the exponential function at line 13 and the main file at line 10. The only thing I can think of is I am not passing the information across the functions correctly?
I hope what I have done doesn't hurt your eyes too badly!

6 件のコメント

Steven Lord
Steven Lord 2017 年 5 月 11 日
What are the full texts (all the words displayed in red) of the error messages you receive when you try running this code?
Henry Migo
Henry Migo 2017 年 5 月 11 日
Error in binarySearch (line 3)
mid = ((bound + mini) / 2);
Error in exponentialSearch (line 12)
binarySearch(array, high, mini, target);
Error in exponentialSearchTestHarness (line 10)
comparisons(searchTarget) = exponentialSearch(array, maxArraySize, searchTarget);
This is the error I get.
Jan
Jan 2017 年 5 月 11 日
This tells where the error is, but the part which explains the cause is still missing.
Henry Migo
Henry Migo 2017 年 5 月 11 日
It gives me nothing more than that. That is everything that comes up in the error box.
Jan
Jan 2017 年 5 月 11 日
What is "the error box"?
Henry Migo
Henry Migo 2017 年 5 月 11 日
The command window at the bottom I assume?

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

 採用された回答

Jan
Jan 2017 年 5 月 11 日

0 投票

Your code:
function [ array, N, mini, target ] = binarySearch( array, N, mini, target)
mid = ((bound + mini) / 2);
The 2nd line fails, because "bound" is not defined here. This should appear in the error message also.

4 件のコメント

Henry Migo
Henry Migo 2017 年 5 月 11 日
ahh thank you, I'll see what I can do to fix it
Joe Blogs
Joe Blogs 2018 年 5 月 7 日
I have a very similiar problem, what steps did you take to resolve the issue?
Marcin Ciepiel
Marcin Ciepiel 2021 年 2 月 21 日
Hey Hey, anyone has any idea how can we fix that code? I was struggling for like 6 hours to make it work, but I don't understand what should we put there
yong wei lin
yong wei lin 2021 年 4 月 19 日
anyone know how to fix that code

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

質問済み:

2017 年 5 月 11 日

コメント済み:

2021 年 4 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by