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?
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 Exchange에서 Simulink에 대해 자세히 알아보기

제품

질문:

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