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 个评论

What are the full texts (all the words displayed in red) of the error messages you receive when you try running this code?
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.
This tells where the error is, but the part which explains the cause is still missing.
It gives me nothing more than that. That is everything that comes up in the error box.
What is "the error box"?
The command window at the bottom I assume?

请先登录,再进行评论。

 采纳的回答

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 个评论

ahh thank you, I'll see what I can do to fix it
I have a very similiar problem, what steps did you take to resolve the issue?
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
anyone know how to fix that code

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by