plotting a line graph

조회 수: 2 (최근 30일)
Alexander
Alexander 2022년 11월 25일
댓글: Alexander 2022년 11월 26일
I have a matirx that is [1 N] and N being a size the enduser chooses. I want to plot the result of matirx in a for loop and update the plot after each iteration.
Example
dice = [0 0 0 0 0 0]
after first iteration
dice = [1 0 0 0 0 0]
2nd iteration
dice = [1 0 0 0 1 0]
This loop well go for X amount times that the endused picks.
  댓글 수: 1
Image Analyst
Image Analyst 2022년 11월 26일
편집: Image Analyst 2022년 11월 26일
What operation are you doing to decide which element of dice to change at each iteration? Is it just a random location? And what do you do with the element once you have decided on which one it is? Do you just set it to 1? Do you toggle it so that 0 goes to 1 and 1 goes to 0?
dice = zeros(1, N);
for k = 1 : X
index = whatever
dice(index) = whatever
end

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

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022년 11월 26일
Here is a list of steps how you can write a short code to get your assignment done:
(1) A user input entry with input()
(2) Write a loop operation.
  • Here I would use dec2bin(ii, 6) to get dice = [0 0 0 0 0 0] for step1, ....[0 0 0 0 0 1] for step 2, ...., etc.
  • Convert the created binary numbers back to decimal using str2double(), E.g.: D = [str2double(dice(1)), str2double(dice(2)), ... str2double(dice(6))]
  • Plot the obtained D values: plot(D), hold all
  • Store legends and add to the plot
  • end of loop
  댓글 수: 3
Alexander
Alexander 2022년 11월 26일
dice = input('What side di do you wish to roll: ')
N = input('please enter how many times you would like to roll the dice: ')
dice_v = [1:dice];
list = zeros(size(dice_v));
precent = zeros(size(dice_v));
upper_limit = (1/dice) + 0.005;
lower_limit = (1/dice) - 0.005;
id = 0;
true_random = 0;
one_fourth = N * 0.25
for i = 1:N
clc
rolls = randi([1 dice],1,1);
id = rolls;
list(id) = list(id) + 1;
precent(id) = list(id)/N;
upper_threshold =
max(precent) - min(precent)
if (threshold > lower_limit && threshold < upper_limit) && (one_fourth < i)
true_random = true_random + 1
if true_random > 3
break
end
pause(1)
else
true_random = 0
end
%plot(list(1))
pause(0.01)
end
Alexander
Alexander 2022년 11월 26일
Here the entire

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

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by