필터 지우기
필터 지우기

values of matrix change on each iteration

조회 수: 1 (최근 30일)
summyia qamar
summyia qamar 2016년 12월 15일
편집: Stephen23 2016년 12월 16일
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

채택된 답변

Stephen23
Stephen23 2016년 12월 15일
편집: Stephen23 2016년 12월 15일
Just use randi:
for k = 1:100
A = randi([1,3],7,3)
end
  댓글 수: 2
summyia qamar
summyia qamar 2016년 12월 15일
편집: summyia qamar 2016년 12월 15일
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 2016년 12월 16일
편집: Stephen23 2016년 12월 16일
"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.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by