Filter löschen
Filter löschen

values of matrix change on each iteration

1 Ansicht (letzte 30 Tage)
summyia qamar
summyia qamar am 15 Dez. 2016
Bearbeitet: Stephen23 am 16 Dez. 2016
if we want a matrix
A=[7x3] such that we iterate 100 times and its values chnage from 1 to 3 randomly on each iteration e.g
A=[1 1 1
2 1 3
1 2 1
3 3 2
3 1 2
1 1 1
2 1 3]
and in next iteration it changes again

Akzeptierte Antwort

Stephen23
Stephen23 am 15 Dez. 2016
Bearbeitet: Stephen23 am 15 Dez. 2016
Just use randi:
for k = 1:100
A = randi([1,3],7,3)
end
  2 Kommentare
summyia qamar
summyia qamar am 15 Dez. 2016
Bearbeitet: summyia qamar am 15 Dez. 2016
thanks but how this works? if I simply use A = randi([1,3],7,3) then only one matrix shows. where is k in it to iterate?
Stephen23
Stephen23 am 16 Dez. 2016
Bearbeitet: Stephen23 am 16 Dez. 2016
"how this works": it generates a new random matrix in a loop, giving exactly what you requested.
"where is k in it to iterate?" I do not understand the question. The loop variable k is not used because it is not required to generate a new random matrix.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by