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));

Respuestas (1)

Stephan
Stephan el 12 de Sept. de 2018
Editada: Stephan el 12 de Sept. de 2018
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 comentario

Stephan
Stephan el 12 de Sept. de 2018
Editada: Stephan el 12 de Sept. de 2018
BTW: The documentation site for hist says:
" hist is not recommended. Use histogram instead."

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 12 de Sept. de 2018

Editada:

el 12 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by