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 comentarios

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

Iniciar sesión para comentar.

 Respuesta aceptada

Jan
Jan el 11 de Mayo de 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 comentarios

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 11 de Mayo de 2017

Comentada:

el 19 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by