How to plot a function file

Hello,
i wrote a function file about a dice game, and i want to plot the progress of the game with a stairs plot, but somehow i can't get the file to plot the results. the file itself works fine, but its just the plotting that i'm stuck with. I tried everything but i can't figure it out. I think i maybe need to attach a vector to the results and then plot this vector but i don't know how.
Hope someone can help me out.
This is what i have for the function file:
function [ y ] = dobbelspel2p
aantalworpen1 = 0;
waarde1 = 0;
while waarde1 < 40
dobbelsteen1 = ceil(6*rand);
dobbelsteen2 = ceil(6*rand);
worp = dobbelsteen1 + dobbelsteen2;
if dobbelsteen1 ~= dobbelsteen2
waarde1 = waarde1+worp;
end
aantalworpen1 = aantalworpen1 +1;
end
while waarde1 < 51
dobbelsteen3 = ceil(6*rand);
if waarde1 + dobbelsteen3 <= 51;
waarde1 = waarde1 + dobbelsteen3;
end
aantalworpen1 = aantalworpen1 +1;
end
aantalworpen2 = 0;
waarde2 = 0;
while waarde2 < 40
dobbelsteen1 = ceil(6*rand);
dobbelsteen2 = ceil(6*rand);
worp = dobbelsteen1 + dobbelsteen2;
if dobbelsteen1 ~= dobbelsteen2
waarde2 = waarde2+worp;
end
aantalworpen2 = aantalworpen2 +1;
end
while waarde2 < 51
dobbelsteen3 = ceil(6*rand);
if waarde2 + dobbelsteen3 <= 51;
waarde2 = waarde2 + dobbelsteen3;
end
aantalworpen2 = aantalworpen2 +1;
end
if aantalworpen1 < aantalworpen2
y = 1;
aantalworpen1
elseif aantalworpen1 > aantalworpen2
y = 2;
aantalworpen2
else aantalworpen1 == aantalworpen2
y =0;
aantalworpen1
end
plot(waarde1,waarde2,'r-')
hold on
end
_

3 comentarios

John D'Errico
John D'Errico el 13 de Dic. de 2016
But nobody really knows what you are trying to do here, what you are plotting and why. All we know is it is some form of dice "game", where we have no indication of the rules. Add that to unreadable, poorly formatted code, with no comments.
If you really want help in a timely fashion, then you need to make more of an effort. Or talk to your instructor, or to your fellow students.
Jan
Jan el 13 de Dic. de 2016
@Thibault Franssens: Please explain clearly: What do you get now? What do you want to get? What have you tried (post the code instead of calling it "everything") so far and which problems do you have?
Rena Berman
Rena Berman el 20 de En. de 2017
(Answers Dev) Restored Question.

Iniciar sesión para comentar.

Respuestas (2)

Massimo Zanetti
Massimo Zanetti el 13 de Dic. de 2016
Editada: Massimo Zanetti el 13 de Dic. de 2016

0 votos

Given a vector y of dice outcomes, plot the stairwise graph like this:
y = [0,3,5,9,2];
X = [0,repelem(1:length(y)-1,2),length(y)];
Y = repelem(y,2);
plot(X,Y,'r');
the result is:

Categorías

Más información sobre Word games en Centro de ayuda y File Exchange.

Preguntada:

el 13 de Dic. de 2016

Respondida:

el 1 de Feb. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by