plotting a line graph

2 views (last 30 days)
Alexander
Alexander on 25 Nov 2022
Commented: Alexander on 26 Nov 2022
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 Comment
Image Analyst
Image Analyst on 26 Nov 2022
Edited: Image Analyst on 26 Nov 2022
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

Sign in to comment.

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 26 Nov 2022
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 Comments
Alexander
Alexander on 26 Nov 2022
Here the entire

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by