필터 지우기
필터 지우기

how to add value after every 5 second

조회 수: 2 (최근 30일)
singh
singh 2015년 5월 6일
댓글: Star Strider 2015년 5월 7일
hello friends i wish to add a number after every five second for the one minute
suppose i wish to get random number from -2 to 2 and store this no and after five second another random number will be get from -2 to 2 and add with the stored no and result of this no will be store again after five second new random no will be get from -2 to 2 and add with stored no(resulted no) this process will be run for a minute it means 12 time i get the random number and add this no if it is possible then how?
p=randi(-2,2);
thanks in advance

채택된 답변

Star Strider
Star Strider 2015년 5월 6일
I would save your data to a vector, then add the random numbers afterwards:
T = 1:60; % Original Vector (Created)
Tm = reshape(T(:), 5, []); % Create Matrix From Column Vector
p = randi([-2 2], 1, size(Tm,2)); % Generate Random Numbers
Tm = [Tm; p]; % Add Random Numbers To Matrix
T = reshape(Tm, [], 1); % Regenerate Column Vector
  댓글 수: 2
singh
singh 2015년 5월 7일
star thanks for the solution but star i have required only p values and addition of all p values
Star Strider
Star Strider 2015년 5월 7일
My pleasure.
The p values are computed separately, so you can add them using the sum function.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 5월 6일
Do you want 5 simulated seconds (that might take only a fraction of a second to simulate), or do you want to have MATLAB wait doing nothing for those five seconds?
Have a look at creating a timer object. See overview here

카테고리

Help CenterFile Exchange에서 Number games에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by