also, did I make it start at x=100 correctly? I'm not sure if I did it right-- I'm a beginner at MATLAB
How to have multiple comet functions all in one graph?
13 ビュー (過去 30 日間)
古いコメントを表示
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 件)
KSSV
2020 年 4 月 15 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!