Hi, I am trying to use rand , but Im getting erros Size inputs must be scalar.
I am almost new at matlab and was wonder how to fix that problem
D = 2 ;
g =1000;
sigma = 1;
for i=1:g
r = rand(0,sigma^2,[D 1]);
%...
end

 채택된 답변

Walter Roberson
Walter Roberson 2019년 2월 25일

1 개 추천

When you talk about sigma^2 you are talking about normal distribution (typically) not uniform distribution such as rand() produces.
I suspect you want to call normrnd() rather than rand() .

댓글 수: 3

Thanks so much!. It worked.
But now I cant make xh equal to r and xp. Matrix dimensions must agree
xp = xl+(xu-xl).*rand(0,1) ;
xh = xp + r;
rand(0,1) means that you want an array with 0 rows and 1 columns .
Perhaps you want normrnd(0,1) ?
The code lines you are using are like what you would use to create a uniform random number in the range xl to xu . If you want to do that once for each member of r, then
xp = xl + (xu-xl) .* rand(size(r));
xh = xp + r;
Thanks again ! haha

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2019년 2월 25일

댓글:

2019년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by