Pick a value from random matrix

1 回表示 (過去 30 日間)
diah Lestari
diah Lestari 2020 年 4 月 22 日
回答済み: Mehmed Saad 2020 年 4 月 22 日
I have a 1x5 matrix with the same value.but the value in the matrix is ​​random, and it changes every time i run (not fixed value). I want to make a new variable to store a value from the matrix. can you help me please? example
A=[z,z,z,z,z] (random)
B=z

回答 (1 件)

Mehmed Saad
Mehmed Saad 2020 年 4 月 22 日
if you always want the same value from a random generator check the following link
otherwise suppose you have 10 iteration and want to store 10 different random numbers in B then
B = zeros(1,10);
for i =1:10
z = rand(1);
A = [z z z z z];%you can use A = repmat(z,1,5);
B(i) = z;
end

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by