please animate my program
Show older comments
hi everyone
i am new to matlab and i have written a small program in it showing two barrier line with blue at -10.0 and 10.0 and 4 points with different colours randomly moving within these two barrier. Here it is:
clf;
hold on;
plot([2.0,2.0,2.645654364963203,2.5564600732869036,1.5105734136458957,0.899934407248229,1.2684019136169957,3.5443697624096333,4.90564875255898,4.361302963699364,2.1868277192242247,-0.30777183171091727,-4.893909494344086,-6.027622886293498,-5.1963029750512435,-2.3456482113770334,2.6516823594965735,3.8861015382741444,3.234467621013309,1.2324966819848688,1.0851937378493863,-1.0909372709822578,-4.837699212286584,-5.900647171774053,-4.817886123668706,-1.5928938491311713,-0.6695144412470846,0.3845894700906598,2.500776201254286,4.699455573649483,6.111049966922457,6.290714707719081,4.572933021252505,2.6263975227630274,2.622738475235838,4.643712797184206,8.757216807951163,13.137060843520132,14.261713930903351,13.42359896958067,10.65778224265799,5.938888483849849,2.8181524852911592,1.361838931376223,1.9334819053244154,4.424640029067437,5.141919845768566,7.74253636891039,9.040959404671051,8.402140967650414,5.89141720332106,1.858157762180852,-0.9675890727174035,-3.460889666195819,-3.9254067806921973,-2.415825944475967,0.984877842951609,4.081388950791247,5.191159274176217,4.170567106540001,1.2952976373129808,-1.692743626285941,-6.6927436262859406,-7.647653588438591,-6.682995893682476,-3.6799700910621826,0.7896234659531967,3.3181010303388456,3.845260791434523,2.4893291671953213,-0.22550248979787257,-0.8216457708857835,-1.302012294406383,-1.3169579400637286,-0.42746610483763825,0.30274418627302446,0.24324875146463404,-1.685540083925634,-4.7702910385369695,-5.835271329522603,-4.816301520352005,-1.9368069549396476,2.538877588145542,7.081097846096055,7.931932199548232,6.779940102837118,3.4993954540621464,-0.572819603298456,-4.84325307502597,-5.81359631071491,-4.693132014765629,-1.432215311667309,1.770376402107443,3.2864891214710976,2.706541123629424,0.18141281699439427,-4.178945743327379,-6.722235392644249,-7.313029127004599,-7.811307078760105,-10.286756231800052], [2.0,2.0,1.1452511079213965,2.401635596229126,2.736901908059435,4.647411285497714,6.688377352738428,7.723054352531454,6.74193702974724,3.7903780582324553,-1.1297889823209828,-6.129788982320983,-7.078919846474328,-5.952221249164301,-2.9550889582659994,1.9195044006721536,6.836987632430832,7.721396615981757,6.655593124384987,4.102453321712378,3.5211197156738354,0.9843193780849404,-3.3551871543469813,-4.28194015355302,-3.175684008977309,-1.2114456667791644,-1.3881293077798205,0.3788537187576171,1.7256390120487384,1.172134372951017,-1.5076711095107869,-4.203221469902623,-9.043460075719683,-10.448149562073827,-9.851305904302311,-7.20046437225853,-2.507043015259155,2.492956984740845,3.595610296310209,2.6940923493698548,-0.1865249783768328,-5.017609193454955,-8.050648726334451,-9.0468497205605,-8.150271468436527,-5.1458231568149735,-2.7619785252120908,1.6258608926225868,2.5135023832247048,1.5415678720757549,-1.3193505877717868,-6.285313921608686,-7.345062108868673,-6.345786874226467,-3.231438021436983,1.7009019541940362,6.645033262270687,11.351946631147527,12.298654708220896,11.233960922501248,8.24924282907941,4.22185604195821,0.8611470664699454,-0.8285934965853072,-1.7272912600096717,-0.47990341851643437,2.639127638789801,7.543816142096019,8.545538920091406,7.433530781537049,5.969433482201877,5.270250537901669,3.659073919447723,4.000191544823261,6.184534396549059,9.246500680294588,12.030194045154307,12.82208741953641,11.487425120670892,11.78636229615143,13.98120651410352,18.146240493090097,23.1022613097357,27.01765445800566,27.998247004610793,26.996677584528513,24.11850974496057,19.229162664230138,14.912358972985867,13.896598096312701,14.779564343486712,17.57184642536526,20.81674539693328,21.69632430793913,20.46289351457327,17.155899928787733,12.162042068789791,9.208027086044854,7.6012098412177895,6.577013630953398,3.4999776043094664], 'b:.'); % point id:1
plot([2.0,2.0,2.641636490643717,2.470129344746113,1.6006334246666538,0.09114589404286555,-1.4679169227594484,-2.2741490325058553,-2.240033762890976,-1.2494534234955874,0.5125220481084192,2.151785382897736,5.814923971901899,6.66921199499139,5.581329232070136,2.426899293050959,-1.1140793787902745,-2.6667604868682444,-2.190880175844553,0.21402480921835343,2.801011874343046,5.575465229920574,6.741123719192597,5.823108475637069,2.8853238897660924,-0.2875746959730283,-1.2660504641833081,-2.807952951361618,-2.4024935324636774,-0.15625627906283812,3.2753849436226665,8.228072870453813,12.59435700124158,13.64974187312754,12.693267936055461,9.774541905187782,5.750500656027791,2.3677602196579124,1.2510786311954933,1.7458869536414152,4.199917998240823,7.531708949274993,9.736097263875422,10.227257226154597,8.788871477128385,5.859011023650721,3.755081670603306,-0.31000187166548887,-1.3933023236169544,-0.4189673114533008,2.6922064941835635,6.955328107565988,8.900967384820948,8.933374496787076,6.995182530356865,2.90868674423895,-0.7945719858278513,-5.794571985827851,-6.787731143562206,-5.8531053876469805,-2.8796388034569906,0.8249457822510102,5.268226949015688,6.281120038429206,5.247675285973945,2.1588368649679595,-2.8411631350320405,-5.467256866511234,-6.193811458508839,-5.0369261074249145,-2.216777795260486,-1.172200166931938,0.08077453966968906,1.3252103217271762,1.7301493007113873,1.3323507187122425,2.937017218976506,6.494815174097704,7.4585590824984,6.51214235245542,3.6331464296407936,-0.22373223728407998,-2.726534886953208,-3.920691106364802,-3.5086323166129123,-1.6399296367565284,1.7350873991663378,3.8802250503699596,4.132908087371365,2.3257890042197786,-0.05803483540252108,-3.176011235140728,-5.055650126915559,-5.4181559331659725,-4.6164899811477795,-4.9506562007783295,-5.929418674775591,-7.553503606304851,-10.706425929120059,-12.92507994993618,-13.160810297287387], [-2.0,-2.0,-1.5960559089328406,-3.1162593752410954,-5.521662896185704,-9.78604826846723,-14.64626370470971,-15.602385464755075,-14.58147965490253,-11.677657624921135,-7.127765947542793,-5.994545271458393,-2.892914486952696,-1.7743985318328184,-2.6179581702792403,-5.461528150805822,-6.389135421609934,-5.18482566231655,-2.0506730200550574,2.9493269799449426,5.3636476571784435,6.715681055378756,6.427068628919277,4.393440864468181,0.27042340284351063,-2.4153133141451186,-2.9783659649399183,-5.641273506860548,-6.256806703493859,-4.743371142906017,-4.3145150022210235,-2.124511097419153,1.945100283846493,2.958677093308574,1.9179184980036523,-1.0697534090851648,-3.976852761926271,-4.921210687074087,-3.7797044998577616,-0.5722617648176267,4.427738235182373,7.120521825649185,7.745727918388317,6.344862925838365,2.9000499538578604,-1.32272955043776,-2.336424660354962,-2.0274327137930896,0.2665275483443459,4.6274383147262075,9.627438314726207,12.89692506225585,13.957740012527564,12.912928122576774,9.965084026164451,5.161488742378485,0.26798925813324814,-4.732010741866752,-5.684325111582043,-4.5402641117930225,-1.5062762900364768,3.420014613543508,6.132389973396981,7.522706995064313,7.184697930489124,4.901440894809273,0.7556388202194215,-0.15324033590919195,1.0843382411176283,3.7416558118546006,7.601962548939522,11.793354273207601,14.38402486591988,14.843516238848565,13.335287504969303,10.382883836147672,9.543224315665706,8.534003307164909,5.608461795181772,0.6638141475117791,-4.334389448903944,-9.334389448903945,-10.218352956122823,-9.034535938453484,-5.940955026643465,-0.9663859537048474,3.991935027448637,6.695046235040262,7.407111458730542,5.981461195170959,4.465024492076652,1.121368244947127,0.1778793770011099,1.255524088774072,1.8824633835565783,4.555409320778314,9.190252291978073,10.184805088183516,9.165444924512455,8.66743788899096,9.244182748782286], 'g:.'); % point id:2
plot([-2.0,-2.0,-2.6382020172748573,-2.443602863792622,-1.354685967624242,0.02700582115438599,1.2400901982140946,2.1292825441098975,1.8626129885419402,1.195573220381181,-0.09368437629308679,-1.3680878831304593,-1.9926343277281204,-1.2567000129984978,0.670373649786246,2.94362690219085,4.4469687821704245,7.045535653889195,7.721824080325189,6.388150978711022,3.0148399338259972,1.8830296977559968,1.207745284013296,-1.3296673139177746,-2.217570558385349,-1.123864811331834,2.0334619362319204,7.03346193623192,9.88132281617677,10.680626907192702,9.513345303953795,7.751240083976906,7.99548840311442,9.673974210232736,10.596977763204146,10.334077667454949,9.174231742101487,7.656835459184873,5.951122531126319,4.312424055934693,3.402263516992576,3.441739048299932,4.415978282900174,5.937553873607468,5.562173782436105,5.940774800090159,8.224726578832009,12.106449886708477,13.13813354223891,12.050999997035822,9.091582922235357,5.156152085970758,2.3841201153210116,1.6823027544001556,1.9577139233957377,2.2871182300126542,1.973216300571865,3.7384694155312417,3.5200910801329908,1.1622717702298369,-2.5760621759873854,-5.737413144747764,-7.854567800508594,-8.053127838741817,-6.184335961108246,-2.2997905273236516,0.8716292000560593,2.708486442281174,2.9283377268437403,1.1949656702359792,-2.412943632618447,-7.26356719478789,-8.368564913662436,-7.500075124391179,-4.763058958844871,-0.12670370666769593,0.9721337477739991,0.16121769216980641,1.3230302352828507,2.0851533233915447,2.0926519834827038,1.3955447971443768,0.857396005694349,-1.1129712791286908,-1.6065820477451904,-0.7345765387338651,0.8833222905236336,1.8865242831582036,3.5049288581143756,3.1766241924604426,1.256102331516812,-0.8794335558419637,-3.8143931448305257,-5.074756997694332,-4.739528681446151,-5.764382716524067,-8.66501077866497,-9.451243096331567,-8.42326826230757,-7.061767753114872,-6.484490640924784], [2.0,2.0,3.0649579335146147,4.402468610635,6.209811809964947,8.488643423482051,11.427934175127758,12.258927199554375,11.112336516301681,7.974862975747782,3.0599535931020885,-0.713789854733053,-1.5836607018126712,-0.40759418122862523,2.5035529359151,7.3768186112404885,9.224719315883513,10.975251947717226,10.865607661113415,8.8421935664322,4.898178576148448,3.9571769191805473,3.454227130748562,1.288678118032029,-0.6598278525946084,-0.9308196222424016,-1.5230410205088742,-0.8553280715729661,1.0840669339364706,0.9248807631035678,-1.3543157732106867,-4.580776412916835,-9.580776412916835,-11.285073016674554,-12.50733652187695,-13.886762581692759,-15.99337652632531,-19.643328630634983,-20.68959715095053,-23.677748676333053,-24.577377757260045,-23.54957362776792,-20.517316654161696,-15.786141132908408,-11.49255489178515,-6.492554891785151,-1.4925548917851508,3.5074451082148492,4.645302282987084,3.860765212765624,1.102591390323791,-3.6335903108369014,-6.394723460019025,-7.272553278744027,-6.200114500007578,-3.498030033078873,-1.8197604191185193,-0.3637260009513452,1.9215114204569697,4.229892734262445,5.706607232426939,6.607168526564058,7.873821362899017,10.621553217511138,15.399889687276419,18.708629126366155,19.738204671909504,18.748767774575022,15.697118447072302,10.697118447072302,5.697118447072302,0.698394281189211,-0.4027603621304763,0.5626208504910712,3.4971395398706466,8.269208162521771,9.292633629181823,11.094089894078778,13.800659402755544,16.257083403357807,19.30162847173955,23.92484119801547,25.133609814437644,24.401212289710067,23.46090495650005,22.699279219295395,19.98711771904059,17.06426838977068,14.862092374112413,12.150368832924745,8.184672315584034,7.213504857255096,4.192500941080747,3.3145450832393024,4.310309247780234,3.3199052448429085,1.2605326832568324,1.13275082223911,3.0198042429190903,4.385894643632039,5.214151179163718], 'r:.'); % point id:3
plot([-2.0,-2.0,-2.652439695394306,-2.578111884035207,-1.864299051678541,-1.007443100736701,-0.7769224290539551,-2.4434984947390554,-3.100893715303704,-2.299789855955157,-0.12636530548307245,2.4714096539887684,4.573450658830359,5.564515782179218,5.067241847416666,3.3085804590728944,0.7884624617818323,-2.5894622183224785,-3.5984323832060423,-2.484946320850904,-1.6515561110788233,0.05265382744779057,3.759501292126046,7.222465830677912,10.184063974441345,11.091165404355975,9.963859668840882,6.735723491939056,1.7357234919390558,0.7270254318956244,1.6648846530820665,1.9752306680435383,3.295554702596345,6.307101159742707,10.416815485634281,11.27183257348613,10.023608976668386,8.091161955530078,5.390454480290691,4.726025474395321,5.26269923995328,6.145136428316143,6.783106131231041,7.105488916740074,9.315559071373444,9.849147382281249,8.55035596708791,6.48049770247753,4.411126458108407,2.943708723072719,2.2377592248598015,2.5817944538305584,3.610998265764015,4.300848712045464,3.9864060315046723,2.738567844947026,1.0550634076215333,-2.0047469463909673,-4.208720282511191,-4.285964243504708,-2.692614258213201,-1.4812364979423485,-0.07379805231054237,-0.0994487203113731,-1.778621405717349,-4.057069154475044,-5.8467689397294045,-6.455435956510611,-5.501599614631123,-2.498607651446153,2.0782658287885116,6.974365488224408,7.941389230962218,7.000465372774591,4.019582424579994,-0.30032940677316766,-2.918240225635679,-3.730789524114531,-2.5183866365865097,0.6813597983754112,3.8524836106114293,5.4884231840794335,5.0611340445469075,3.0332565423008973,0.1904597302252422,-2.737826079567073,-5.402282280112912,-5.921421000497433,-4.536491370256503,-1.0313104611637192,0.9857577472459589,1.9466267736377199,2.10727278450324,0.2422660645275272,-2.1283685226319746,-2.607708594566026,-0.9504178495433995,-1.1381397460196732,-3.443427961529607,-6.483256476637505,-7.418376169461012], [-2.0,-2.0,-2.4543093285573634,-2.2818407325641514,-0.7160893988488561,2.0266711240192175,5.802376032449303,6.7108912451935625,9.727141635957498,14.613842547374551,19.56462614163977,24.50181653836363,25.460163556763565,24.327139189194806,21.217225825677687,16.217225825677687,11.217225825677687,6.2877871708192155,2.479330861306465,1.2130603451172353,0.08973154174397124,-0.1706090928902229,1.7041673710922354,4.090959165775342,5.655323355554797,5.361165948328423,3.0673629062685497,-1.133023495746032,-6.133023495746032,-7.0129620805059165,-5.816637368001705,-5.455899933926853,-4.708137663520293,-2.612896345034793,0.5088307196846107,2.4127331168611383,2.4522324387862877,0.4794285882153466,-3.45673125944702,-4.386647923509246,-6.394086674848243,-10.522205553114846,-13.439329759413,-15.764235449368208,-16.836366804627335,-19.80526268542327,-24.63678076762892,-29.63678076762892,-30.603627444030856,-29.53139911014815,-26.43363037912903,-21.43363037912903,-16.52937665794748,-13.896335748375947,-10.817774988189193,-6.596506359390323,-1.709714478490759,1.4736437022270765,5.322309390815519,8.19880805534918,10.104557280593255,9.881064393749215,10.002501320256814,8.781808177905976,6.119166919299337,1.4785300343785224,-1.8963635168797413,-2.860966406164515,-2.2778612489356993,0.22085901855313583,4.724700374452943,8.947338867381278,10.085107744347843,9.28999972751105,6.438145002844623,2.3210354634822297,1.357844912090683,2.5075268344117045,5.734270213583635,9.49512110305575,14.321711734075706,15.383585592795523,14.42263630221044,11.411607848116985,6.411607848116985,1.8696215794143773,0.9080569541077421,1.857567296235757,4.835342789761856,8.118155867831309,10.279860602837184,10.379236072131814,8.40519461671056,4.528612924255281,3.169863436733,3.8328399778975752,6.462405278894704,7.544069986679835,7.233931144915632,6.258683664311816,7.244546015591333], 'c:.'); % point id:4
plot_lines(10.0,[],'b'); % (end) fence id:1
plot_lines(-10.0,[],'b'); % (end) fence id:2
I want these points can be seen moving at their respective coordinates and remaining within the two barrier.
Thanks.
Answers (1)
Image Analyst
on 7 Apr 2012
or maybe you can use the comet() function:
t = 0:.001:2*pi;
x = cos(2*t).*(cos(t).^2);
y = sin(2*t).*(sin(t).^2);
comet(x,y);
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!