How to have multiple comet functions all in one graph?
Ältere Kommentare anzeigen
Hi guys! I'm working on a school project but I am having trouble combining multiple comet functions into one graph. The assignment asks: A family with 10 kids is an ensemble – each child is unique and has its own “destiny”. You will have a family of simulations –each simulation will take 2,500 steps. Each simulation will have 2,500 steps. Start with X = 100. This is the code I have so far, but I am stuck on how to have create 10 unique multiple comets/graphs all fitted into 1 figure. I'm not sure if this is even possible, but I wanted the assignment to look clean. And if it is possible, how can I also incorporate a legend to identify which trail is which child? (I stopped the code at child 2 just to save space for this question-- but in my matlab it goes to 10)
%% System Clearing
clc;
clear all;
close all;
%% Walking/step Conditions
stepsL=1; %stepping to the left
stepsR=1; %stepping to the right
%% Individual Walking for-loop (CHILD 1)
for n = 100: 2500 % starting at 100
x = rand ;
if (x >= 0.5)
stepsL = stepsL + 1; % if moving left
else
stepsR = stepsR + 1; % if moving right
end
location(n) = stepsL - stepsR; % location tracker for direction
end
comet(location)
title('Child 1')
xlabel('number of steps')
%% Individual Walking for-loop (CHILD 2)
for n = 100: 2500 % starting at 100
x = rand ;
if (x >= 0.5)
stepsL = stepsL + 1; % if moving left
else
stepsR = stepsR + 1; % if moving right
end
location(n) = stepsL - stepsR; % location tracker for direction
end
comet(location)
title('Child 2')
xlabel('number of steps')
1 Kommentar
Kylie Ellis
am 15 Apr. 2020
Antworten (1)
KSSV
am 15 Apr. 2020
th = linspace(0,2*pi,10^3) ;
x0 = cos(th) ;
y0 = sin(th) ;
x = th ;
y = [x0 ; y0] ;
for i = 1:length(th)
plot(x(1:i),y(:,1:i))
axis([min(x) max(x) -1 1])
drawnow
endfor
4 Kommentare
Kylie Ellis
am 15 Apr. 2020
KSSV
am 15 Apr. 2020
Simple we are plotting it in a loop...and updating the lot.
Kylie Ellis
am 15 Apr. 2020
KSSV
am 15 Apr. 2020
I have taken it for demo....you should extend it for your case.
Kategorien
Mehr zu Discrete Data Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!