필터 지우기
필터 지우기

Too many input error when generating random number using exponential distribution

조회 수: 1 (최근 30일)
Hi everyone,
I want to use command "random" to generate 1000*1 vector, each elements of this vector are random drawn from Exponential distribution whose mu=0.1. This is my code:
pd = makedist('Exponential','mu',0.1);
Y=random(pd,1000,1);
When i run this in MATLAB, there is an error:
I also try some other distributions, but the command "random" ONLY works with normal distribution.
Please help, thank you!
  댓글 수: 4
Steven Lord
Steven Lord 2023년 11월 14일
Please also show the output of:
which -all exprnd
/MATLAB/toolbox/stats/stats/exprnd.m
欣元
欣元 2023년 11월 14일
Many thanks for you two! I add the information you asked in the following pictures:
My classmate also ran my code in her MATLAB and there is nothing wrong ,so I guess the problem may stem from my MATLAB ifself (maybe some m documents loss?).

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

채택된 답변

Steven Lord
Steven Lord 2023년 11월 14일
The exprnd function in D:\dynarc\5.4\matlab\missing\stats\exprnd.m is taking precedence over the exprnd function included in Statistics and Machine Learning Toolbox. That function doesn't have the same signature (doesn't accept the same number and/or type of inputs as the toolbox function.) While it is ahead of the toolbox directory on the MATLAB search path, you will not be able to use the function from the toolbox. I would rename it, remove it, or remove the directory containing it from the MATLAB search path.

추가 답변 (2개)

Cris LaPierre
Cris LaPierre 2023년 11월 14일
You have a function that is shadowing the builtin exprnd.m file. Rename your file (the one at D:\dynarc\5.4\matlab\missing\stats\exprnd.m)

欣元
欣元 2023년 11월 15일
Thank you guys for you help!
Actually dynare is a very useful package (from https://www.dynare.org/) for researchers in macro economics. I don't want to rename or remove the file "exprnd.m" in D:\dynare\5.4\matlab\missing\stats, otherwise I will meet some problem when using dynare package. But thanks to your suggestion, I come across with the following solution:
If I want to use basic MATLAB functions, I would remove the dynare folder from the MATLAB search path.
If I want to use dynare package, I would add the dynare folder to the MATLAB search path.
This solution allows me to switch over "exprnd.m" in MATLAB and "exprnd.m" in dynare (but I think the authors of dynare should have considered that some of their functions have the same name with basic MATLAB functions).
You guys are really professional and helpful! I will try to accept both the answer from Steven Lord and Cris LaPierre (if possible). Have a nice day!

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by