How do I store all values of a loop in a vector?

조회 수: 2 (최근 30일)
Matthew
Matthew 2024년 4월 12일
댓글: Dyuman Joshi 2024년 4월 19일
for i=1:100000;
x=randi(6)+randi(6);
end;
I am trying to find an average across all values of x and need to save them all as a vector and can't figure out how
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2024년 4월 19일
An alternate method without loop -
x = randi(6,1,1e5) + randi(6,1,1e5);

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

채택된 답변

Voss
Voss 2024년 4월 12일
x = zeros(1,100000);
for i=1:100000
x(i)=randi(6)+randi(6);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by