Why do I recive the error "Attempt to execute SCRIPT hist as a function: /Users/Tru​lsKnarvik/​Documents/​BI/Master/​4. år/1. semester/E​conometric​s/MATLAB/h​ist.m Error in tabulate (line 52) [counts values] = hist(y,(1:maxlevels));"

Attempt to execute SCRIPT hist as a function: /Users/TrulsKnarvik/Documents/BI/Master/4. år/1. semester/Econometrics/MATLAB/hist.m
Error in tabulate (line 52) [counts values] = hist(y,(1:maxlevels));

Answers (1)

Hi,
rename your script. hist is a matlab function and it causes the problem if you save your script with the same name. Call it histo.m for example to avoid problems. This is because if you call the MATLAB hist function:
[counts values] = hist(y,(1:maxlevels));
Matlab searches for this function and finds your script as first. Then it tries to call this script with the input arguments:
y,(1:maxlevels)
Since your script is not a function accepting inputs it throws the error. Even if your script were a function that accepts inputs, that would certainly not be what you want to achieve with your code. What you want to do is calling the MATLAB hist function.
In general NEVER name your scripts with names of MATLAB functions.
Best regards
Stephan

1 Comment

BTW: The documentation site for hist says:
" hist is not recommended. Use histogram instead."

Sign in to comment.

Asked:

on 12 Sep 2018

Edited:

on 12 Sep 2018

Community Treasure Hunt

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

Start Hunting!