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

답변 (1개)

Stephan
Stephan 2018년 9월 12일
편집: Stephan 2018년 9월 12일
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

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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

질문:

2018년 9월 12일

편집:

2018년 9월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by