Error using rand Size inputs must be scalar.

22 vues (au cours des 30 derniers jours)
Cesar Ramirez
Cesar Ramirez le 25 Fév 2019
Commenté : Cesar Ramirez le 25 Fév 2019
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

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Fév 2019
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 commentaires
Walter Roberson
Walter Roberson le 25 Fév 2019
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;
Cesar Ramirez
Cesar Ramirez le 25 Fév 2019
Thanks again ! haha

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by