Error when generating a for loop with unifrnd

11 ビュー (過去 30 日間)
EM geo
EM geo 2018 年 7 月 4 日
コメント済み: EM geo 2018 年 7 月 5 日
I have to generate 1000 times 12 numbers with values between 0 and 6. I've tried to write this scrpt but there is an error:
a = 0; b = 1:6;
for i = 1:1000;
r(i) = unifrnd(a,b(6),1,12)
end
The error is: In an assignment A(I) = B, the number of elements in B and I must be the same.

回答 (1 件)

Dennis
Dennis 2018 年 7 月 4 日
r(i) only has 1 field and you try to store 12 values. Try
a = 0; b = 1:6;
r=zeros(1000,12);
for i = 1:1000;
r(i,:) = unifrnd(a,b(6),1,12);
end
  1 件のコメント
EM geo
EM geo 2018 年 7 月 5 日
really thanks!!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by