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 commentaires

Steven Lord
Steven Lord le 11 Mai 2017
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.
Jan
Jan le 11 Mai 2017
This tells where the error is, but the part which explains the cause is still missing.
Henry Migo
Henry Migo le 11 Mai 2017
It gives me nothing more than that. That is everything that comes up in the error box.
Jan
Jan le 11 Mai 2017
What is "the error box"?
Henry Migo
Henry Migo le 11 Mai 2017
The command window at the bottom I assume?

Connectez-vous pour commenter.

 Réponse acceptée

Jan
Jan le 11 Mai 2017
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 commentaires

Henry Migo
Henry Migo le 11 Mai 2017
ahh thank you, I'll see what I can do to fix it
Joe Blogs
Joe Blogs le 7 Mai 2018
I have a very similiar problem, what steps did you take to resolve the issue?
Marcin Ciepiel
Marcin Ciepiel le 21 Fév 2021
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 le 19 Avr 2021
anyone know how to fix that code

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink dans Centre d'aide 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