Arrow-size in Quiver - matlab

I want to increase the arrow size in quiver. Apparently, there isn't such a property in matlab.
I tried changing the following in quiver.m
% Arrow head parameters
%alpha = 0.33; % Size of arrow head relative to the length of the vector
%beta = 0.33; % Width of the base of the arrow head relative to the length
alpha = 100000050.5; beta = 0.5;
autoscale = 0; % Autoscale if ~= 0 then scale by this.
plotarrows = 1; % Plot arrows
But it shows no effect. Please use the following example for one of the above curved line.
Reproducible example:
Data:
K>> xcor_i, ycor_i
xcor_i =
-41.9777
-41.9777
-41.9777
-41.9777
-41.9778
-41.9780
-41.9786
-41.9801
-41.9833
-41.9894
-42.0001
-42.0180
-42.0462
-42.0888
-42.1509
-42.2382
-42.3575
-42.5163
-42.7230
-42.9862
-43.3151
-43.7191
-44.2070
-44.7877
-45.4689
-46.2574
-47.1585
-48.1762
-49.3125
-50.5676
-51.9399
-53.4262
-55.0215
-56.7195
-58.5131
-60.3942
-62.3547
-64.3866
-66.4821
-68.6343
-70.8372
-73.0858
-75.3760
-77.7045
-80.0689
-82.4667
-84.8956
-87.3524
-89.8334
-92.3332
-94.8451
-97.3606
-99.8694
-102.3593
-104.8170
-107.2277
-109.5757
-111.8454
-114.0213
-116.0888
-118.0353
-119.8499
-121.5249
-123.0557
-124.4415
-125.6852
-126.7938
-127.7782
-128.6532
-129.4366
-130.1496
-130.8154
-131.4592
-132.1069
-132.7845
-133.5170
-134.3276
-135.2369
-136.2618
-137.4148
-138.7034
-140.1298
ycor_i =
-14.2165
-14.2165
-14.2165
-14.2165
-14.2166
-14.2167
-14.2172
-14.2183
-14.2204
-14.2245
-14.2315
-14.2430
-14.2606
-14.2866
-14.3235
-14.3742
-14.4417
-14.5296
-14.6411
-14.7797
-14.9487
-15.1511
-15.3895
-15.6657
-15.9813
-16.3369
-16.7324
-17.1672
-17.6399
-18.1484
-18.6901
-19.2620
-19.8604
-20.4815
-21.1211
-21.7749
-22.4386
-23.1078
-23.7785
-24.4469
-25.1094
-25.7626
-26.4037
-27.0299
-27.6391
-28.2298
-28.8014
-29.3543
-29.8905
-30.4131
-30.9272
-31.4388
-31.9555
-32.4856
-33.0377
-33.6205
-34.2420
-34.9091
-35.6278
-36.4023
-37.2352
-38.1276
-39.0788
-40.0868
-41.1479
-42.2574
-43.4099
-44.5989
-45.8179
-47.0600
-48.3185
-49.5871
-50.8597
-52.1303
-53.3934
-54.6435
-55.8751
-57.0827
-58.2606
-59.4031
-60.5046
-61.5596
Code:
vx=diff(xcor_i);
vy=diff(ycor_i);
goal_vec_x=xcor_i(2:end);
goal_vec_y=ycor_i(2:end);
quiver(goal_vec_x,goal_vec_y,vx,vy,'LineWidth',0.5,'MaxHeadSize',100000,'AutoScale','off');

Related

Error using integral (line 85): A and B must be floating-point scalars

I have the following code that I wish to estimate the parameters of a custom distribution using MATLAB's function mle(). For more details on the distribution.
The main code is:
x = [0 0 0 0 0.000649967501624919 0.00569971501424929 0.0251487425628719 0.0693465326733663 0.155342232888356 0.284835758212089 0.458277086145693 0.658567071646418 0.908404579771011 1.17284135793210 1.43977801109945 1.71951402429879 1.98925053747313 2.27553622318884 2.57147142642868 2.80390980450977 3.03829808509575 3.26583670816459 3.45642717864107 3.65106744662767 3.81950902454877 3.98275086245688 4.11259437028149 4.24683765811709 4.35043247837608 4.43832808359582 4.58427078646068 4.62286885655717 4.68361581920904 4.75686215689216 4.80245987700615 4.84005799710015 4.86280685965702 4.91675416229189 4.92725363731813 4.90890455477226 4.96570171491425 4.92315384230789 4.95355232238388 4.92790360481976 4.93135343232838 4.90310484475776 4.90885455727214 4.86765661716914 4.85490725463727 4.81940902954852 4.81450927453627 4.78621068946553 4.74206289685516 4.71791410429479 4.69961501924904 4.65706714664267 4.63611819409030 4.60176991150443 4.57512124393780 4.53507324633768 4.48252587370631 4.47062646867657 4.43127843607820 4.39963001849908 4.37598120093995 4.29548522573871 4.31033448327584 4.21708914554272 4.21913904304785 4.18669066546673 4.16719164041798 4.09774511274436 4.07989600519974 4.02869856507175 3.98485075746213 3.95785210739463 3.93945302734863 3.90240487975601 3.87025648717564 3.81185940702965 3.78461076946153 3.74091295435228 3.71666416679166 3.67276636168192 3.65846707664617 3.61361931903405 3.58712064396780 3.55452227388631 3.53082345882706 3.49197540122994 3.48582570871456 3.46512674366282 3.41227938603070 3.36278186090695 3.35528223588821 3.31238438078096 3.27213639318034 3.23863806809660 3.24173791310434 3.19339033048348 3.20118994050298 3.16489175541223 3.10739463026849 3.09484525773711 3.08094595270237 3.02129893505325 3.02309884505775 2.99375031248438 2.95765211739413 2.93230338483076 2.89560521973901 2.87805609719514 2.85440727963602 2.82285885705715 2.80175991200440 2.79091045447728 2.73901304934753 2.72701364931753 2.73441327933603 2.71646417679116 2.68236588170592 2.65551722413879 2.63356832158392 2.60361981900905 2.58147092645368 2.57697115144243 2.54287285635718 2.53502324883756 2.47702614869257 2.50387480625969 2.46487675616219 2.45722713864307 2.42707864606770 2.41762911854407 2.39823008849558 2.38708064596770 2.34058297085146 2.35613219339033 2.32123393830309 2.30503474826259 2.27613619319034 2.27248637568122 2.25113744312784 2.24908754562272 2.22703864806760 2.20583970801460 2.17244137793110 2.15709214539273 2.16469176541173 2.12139393030348 2.12809359532023 2.11389430528474 2.09774511274436 2.07629618519074 2.07459627018649 2.05394730263487 2.04724763761812 2.01684915754212 2.01684915754212 2.00409979501025 1.98955052247388 1.96540172991350 1.95890205489726 1.93035348232588 1.92295385230738 1.90605469726514 1.89785510724464 1.87070646467677 1.88000599970002 1.86295685215739 1.84420778961052 1.82510874456277 1.80480975951202 1.80785960701965 1.80870956452177 1.77581120943953 1.76771161441928 1.77131143442828 1.76636168191590 1.75081245937703 1.73156342182891 1.69876506174691 1.70836458177091 1.70376481175941 1.67196640167992 1.68101594920254 1.66586670666467 1.66061696915154 1.64296785160742 1.63291835408230 1.62506874656267 1.62516874156292 1.60556972151392 1.59007049647518 1.59187040647968 1.57947102644868 1.57577121143943 1.54527273636318 1.57237138143093 1.54637268136593 1.54802259887006 1.50492475376231 1.52077396130193 1.50417479126044 1.50162491875406 1.50062496875156 1.48957552122394 1.47997600119994 1.47027648617569 1.44452777361132 1.45407729613519 1.44272786360682 1.43247837608120 1.41657917104145 1.40787960601970 1.39323033848308 1.40282985850707 1.39403029848508 1.38233088345583 1.37888105594720 1.37943102844858 1.36183190840458 1.34808259587021 1.34503274836258 1.33703314834258 1.33308334583271 1.32253387330633 1.32698365081746 1.29963501824909 1.30758462076896 1.29103544822759 1.29473526323684 1.27413629318534 1.26858657067147 1.27888605569722 1.26063696815159 1.27863606819659 1.25168741562922 1.23913804309785 1.24788760561972 1.22308884555772 1.24198790060497 1.22133893305335 1.20678966051697 1.20098995050247 1.20343982800860 1.18779061046948 1.19024048797560 1.17194140292985 1.17369131543423 1.16869156542173 1.15814209289536 1.15429228538573 1.15904204789761 1.12774361281936 1.15344232788361 1.13744312784361 1.12909354532273 1.12479376031198 1.11099445027749 1.11469426528674 1.11064446777661 1.10464476776161 1.10309484525774 1.10689465526724 1.07654617269137 1.07884605769712 1.07359632018399 1.06864656767162 1.07544622768862 1.06689665516724 1.04884755762212 1.06164691765412 1.04979751012449 1.04529773511324 1.02839858007100 1.03634818259087 1.01709914504275 1.02089895505225 1.01024948752562 1.01549922503875 1.01319934003300 1.01404929753512 1.00839958002100 0.995400229988501 0.989850507474626 0.978801059947003 0.977551122443878 0.980450977451127 0.975451227438628 0.969201539923004 0.964151792410380 0.964601769911504 0.958802059897005 0.955702214889256 0.948602569871506 0.960751962401880 0.941352932353382 0.928653567321634 0.949002549872506 0.937053147342633 0.913854307284636 0.916204189790510 0.915454227288636 0.902604869756512 0.909454527273636 0.895505224738763 0.898355082245888 0.894455277236138 0.902454877256137 0.883705814709265 0.888405579721014 0.876356182190891 0.881555922203890 0.878156092195390 0.868456577171141 0.870406479676016 0.863906804659767 0.862456877156142 0.858757062146893 0.851307434628269 0.851107444627769 0.833908304584771 0.843507824608770 0.831708414579271 0.836858157092145 0.829058547072646 0.828508574571272 0.822908854557272 0.820508974551273 0.815559222038898 0.819709014549273 0.809609519524024 0.813409329533523 0.800759962001900 0.806609669516524 0.806959652017399 0.792260386980651 0.787660616969152 0.783810809459527 0.794960251987401 0.771061446927654 0.788910554472276 0.789510524473776 0.763061846907655 0.776761161941903 0.767561621918904 0.773611319434028 0.750262486875656 0.765811709414529 0.765911704414779 0.748012599370032 0.741612919354032 0.757312134393280 0.752612369381531 0.741362931853407 0.742212889355532 0.741912904354782 0.743162841857907 0.732963351832408 0.732813359332033 0.733363331833408 0.721913904304785 0.716664166791661 0.726713664316784 0.709764511774411 0.700064996750163 0.710764461776911 0.717664116794160 0.707314634268287 0.707114644267787 0.705614719264037 0.709164541772911 0.696665166741663 0.680765961701915 0.686715664216789 0.694465276736163 0.683015849207540 0.681715914204290 0.694465276736163 0.688615569221539 0.680665966701665 0.672316384180791 0.672866356682166 0.656517174141293 0.665316734163292 0.671566421678916 0.666266686665667 0.652917354132293 0.663366831658417 0.651917404129794 0.663816809159542 0.661366931653417 0.647017649117544 0.655167241637918 0.647867606619669 0.636918154092295 0.645467726613669 0.633118344082796 0.640217989100545 0.634668266586671 0.618669066546673 0.635068246587671 0.632568371581421 0.623118844057797 0.623868806559672 0.623718814059297 0.621368931553422 0.623768811559422 0.608419579021049 0.616019199040048 0.609869506524674 0.606569671516424 0.614019299035048 0.610269486525674 0.596520173991300 0.595570221488926 0.593270336483176 0.596670166491675 0.598470076496175 0.597770111494425 0.593720313984301 0.592770361481926 0.585420728963552 0.580870956452177 0.584120793960302 0.580270986450677 0.577971101444928 0.579021048947553 0.572821358932053 0.585970701464927 0.572921353932303 0.567071646417679 0.569971501424929 0.571271436428179 0.568421578921054 0.567421628918554 0.569521523923804 0.563721813909305 0.558772061396930 0.562171891405430 0.557872106394680 0.549072546372681 0.558722063896805 0.536973151342433 0.561021948902555 0.544172791360432 0.552122393880306 0.553072346382681 0.546222688865557 0.551472426378681 0.540772961351932 0.541122943852807 0.542772861356932 0.530323483825809 0.526023698815059 0.529273536323184 0.524573771311435 0.525923703814809 0.524923753812309 0.516474176291185 0.527273636318184 0.527723613819309 0.518424078796060 0.517874106294685 0.516074196290186 0.517924103794810 0.523173841307935 0.514474276286186 0.513174341282936 0.498875056247188 0.518024098795060 0.507924603769812 0.505524723763812 0.507174641267937 0.502874856257187 0.502624868756562 0.500624968751562 0.510824458777061 0.490925453727314 0.492675366231688 0.489925503724814 0.478126093695315 0.485775711214439 0.491775411229439 0.489925503724814 0.491325433728314 0.487225638718064 0.485725713714314 0.485675716214189 0.477676116194190 0.483875806209690 0.478026098695065 0.470176491175441 0.471926403679816 0.483625818709065 0.469376531173441 0.474026298685066 0.467826608669567 0.462426878656067];
Censored = ones(1,size(x,2));%
custpdf = #eval_custpdf;
custcdf = #eval_custcdf;
phat = mle(x,'pdf', custpdf,'cdf', custcdf,'start',[1 0.1 0.3 0.1 0.01 -0.3],...
'lowerbound',[0 0 0 0 0 -inf],'upperbound',[inf inf inf inf inf inf],'Censoring',Censored);
% Cheking how close the estimated PDF and CDF match with those from the data x
t = 0.001:0.001:0.5;
figure();
plot(t,x);hold on
plot(t,custpdf(t, phat(1), phat(2), phat(3), phat(4), phat(5), phat(6)))
figure();
plot(t,cumsum(x)./sum(x));hold on
plot(t,custcdf(t, phat(1), phat(2), phat(3), phat(4), phat(5), phat(6)))
The functions are:
function out = eval_custpdf(x,myalpha,mybeta,mytheta,a,b,c)
first_integral = integral(#(x) eval_K(x,a,b,c),0,1).^-1;
theta_t_ratio = (mytheta./x);
incomplete_gamma = igamma(myalpha,theta_t_ratio.^mybeta);
n_gamma = gamma(myalpha);
exponent_term = exp(-theta_t_ratio.^mybeta-(c.*(incomplete_gamma./n_gamma)));
numerator = first_integral.* mybeta.*incomplete_gamma.^(a-1).*...
theta_t_ratio.^(myalpha*mybeta+1).*exponent_term;
denominator = mytheta.* n_gamma.^(a+b-1).* (n_gamma-incomplete_gamma.^mybeta).^(1-b);
out = numerator./denominator;
end
function out = eval_custcdf(x,myalpha,mybeta,mytheta,a,b,c)
first_integral = integral(#(x) eval_K(x,a,b,c),0,1).^-1;
theta_t_ratio = (mytheta./x);
incomplete_gamma = igamma(myalpha,theta_t_ratio.^mybeta);
n_gamma = gamma(myalpha);
second_integral = integral(#(x) eval_K(x,a,b,c),0, incomplete_gamma.^mybeta./n_gamma);
% |<----- PROBLEMATIC LINE ----->|
out = first_integral*second_integral;
end
function out = eval_K(x,a,b,c)
out = x.^(a-1).*(1-x).^(b-1).*exp(-c.*x);
end
The integral that is causing the problem is the second intergral in the function eval_custcdf() as its upper limit is an array (denoted by PROBLEMATIC LINE).
Is there a way to take a single value from the array x such that the upper limit remains a scalar? And then calculate the cdf such that the output of the cdf is an array? Using a forloop, maybe? But I cannot seem to figure how to implement that?
How can I work around this problem?
Any help would be appreciated.
Thanks in advance.
eval_custcdf is a function expected to return 1D array of length n for
a given n data input.
I use a for loop to compute the output for a given input, then
return the whole array as output of eval_custcdf
I passed the input array elements one at a time
This is how eval_custcdf may look like
function out = eval_custcdf(x,myalpha,mybeta,mytheta,a,b,c)
out = zeros(size(x));
for i = 1: length(x)
first_integral = integral(#(w) eval_K(w,a,b,c),0,1).^-1;
theta_t_ratio = (mytheta./x(i));
incomplete_gamma = igamma(myalpha,theta_t_ratio.^mybeta);
n_gamma = gamma(myalpha);
second_integral = integral(#(w) eval_K(w,a,b,c),0, incomplete_gamma.^mybeta./n_gamma);
out(i) = first_integral*second_integral;
end
end

Simple rotation of a rectangle along a curve in matlab

I'm trying to rotate a rectangle(polyshape) in matlab to orient itself along the curve(a set of points). So far this is my code.
l=2;w=1;xc=-1;yc=2;
xvs= [xc+w/2 xc+w/2 xc-w/2 xc-w/2];
yvs= [yc-l/2 yc+l/2 yc+l/2 yc-l/2];
ax = gca;
polyin = polyshape(xvs,yvs); % %w/2,h/2% polyin = rectangle('Position',[-0.1 -0.1 0.2, 0.4]);
k=2;
% t = acos((y(k-1)*x(k-1)+y(k)*x(k))/(norm([x(k-1) y(k-1)])*norm([x(k) y(k)])));
t = atan(y(k)/x(k));
polyout = translate(polyin,[-xc -yc]);
polyout = translate(polyout,[x(1) y(1)]);
polyout = rotate(polyout, t, [x(2) y(2)]);
plot(polyout);
axis([-4 4 0 50]);
prev_t = atan(y(2)/x(2));
for k=2:length(x)
cla();
t = atan((y(k)-y(k-1))/(x(k)-x(k-1)));
% t = acos((y(k-1)*x(k-1)+y(k)*x(k))/(norm([x(k-1) y(k-1)])*norm([x(k) y(k)])));
% t = atan((y(k-1))/(x(k-1)));
polyout=translate(polyout,x(k)-x(k-1),y(k)-y(k-1));
[t3,t4]=centroid(polyout);
t-prev_t
polyout=rotate(polyout,rad2deg(t-prev_t) ,[t3, t4] );%, );
prev_t = t;
plot(polyout);
hold on;
plot(x(1:k),y(1:k));
hold on;
quiver(x(k), y(k), 1, 1);
axis([-4 4 0 50]);
drawnow;
end
x,y is listed below
x = [-1 -1.00972272933410 -1.01870478051530 -1.02695805761983 -1.03449438259277 -1.04132549543428 -1.04746305438566 -1.05291863611549 -1.05770373590578 -1.06182976783809 -1.06530806497965 -1.06814987956949 -1.07036638320459 -1.07196866702597 -1.07296774190485 -1.07337453862878 -1.07319990808774 -1.07245462146029 -1.07114937039970 -1.06929476722009 -1.06690134508251 -1.06397955818112 -1.06053978192930 -1.05659231314578 -1.05214737024076 -1.04721509340205 -1.04180554478121 -1.03592870867963 -1.02959449173473 -1.02281272310602 -1.01559315466128 -1.00794546116266 -0.999879240452816 -0.991404013641053 -0.982529225289427 -0.973264243598892 -0.963618360595424 -0.953600792316151 -0.943220678995479 -0.932487085251223 -0.921409000270737 -0.909995337997038 -0.898254937314939 -0.886196562237176 -0.873828902090537 -0.861160571701991 -0.848200111584816 -0.834955988124727 -0.821436593766009 -0.807650247197639 -0.793605193539421 -0.779309604528111 -0.764771578703544 -0.749999141594771 -0.735000245906179 -0.719782771703621 -0.704354526600550 -0.688723245944142 -0.672896593001429 -0.656882159145424 -0.640687464041251 -0.624319955832276 -0.607787011326233 -0.591095936181355 -0.574253965092497 -0.557268261977274 -0.540145920162182 -0.522893962568731 -0.505519341899570 -0.488028940824620 -0.470429572167200 -0.452727979090155 -0.434930835281988 -0.417044745142986 -0.399076243971348 -0.381031798149319 -0.362917805329311 -0.344740594620036 -0.326506426772637 -0.308221494366812 -0.289891921996946 -0.271523766458236 -0.253123016932825 -0.234695595175927 -0.216247355701956 -0.197784085970655 -0.179311506573228 -0.160835271418462 -0.142360967918861 -0.123894117176775 -0.105440174170524 -0.0870045279405308 -0.0685925017754495 -0.0502093533982922 -0.0318602751525592 -0.0135503941883670 0.00471522735142232 0.0229315921450729 0.0410937675058457 0.0591968851958715 0.0772361412400196 0.0952067957397721 0.113104172687091 0.130923659778296 0.148660708227926 0.166310832582623 0.183869610534992 0.201332682737479 0.218695752616237 0.235954586185006 0.253105011858973 0.270142920268653 0.287064264073754 0.303865057777052 0.320541377538260 0.337089360987901 0.353505207041178 0.369785175711844 0.385925587926079 0.401922825336353 0.417773330135305 0.433473604869608 0.449020212253846 0.464409774984379 0.479638975553221 0.494704556061906 0.509603318035363 0.524332122235782 0.538887888476493 0.553267595435832 0.567468280471012 0.581487039431996 0.595321026475369 0.608967453878208 0.622423591851952 0.635686768356277 0.648754368912964 0.661623836419772 0.674292670964308 0.686758429637899 0.699018726349463 0.711071231639382 0.722913672493370 0.734543832156346 0.745959549946308 0.757158721068200 0.768139296427783 0.778899282445511 0.789436740870399 0.799749788593894 0.809836597463747 0.819695394097884 0.829324459698281 0.838722129864827 0.847886794409204 0.856816897168752 0.865510935820345 0.873967461694257 0.882185079588040 0.890162447580389 0.897898276845016 0.905391331464524 0.912640428244272 0.919644436526252 0.926402278002956 0.932912926531251 0.939175407946249 0.945188799875176 0.950952231551246 0.956464883627534 0.961725987990839 0.966734827575568 0.971490736177594 0.975993098268136 0.980241348807631 0.984234973059598 0.987973506404514 0.991456534153687 0.994683691363123 0.997654662647400 1.00036918199354 1.00282703257487 1.00502804656492 1.00697210495126 1.00865913734939 1.01008912181662 1.01126208466593 1.01217810027981 1.01283729092421 1.01323982656233 1.01338592466854 1.01327585004223 1.01290991462170 1.01228847729801 1.01141194372885 1.01028076615244 1.00889544320138 1.00725651971651 1.00536458656082 1.00322028043328 1.00082428368272 0.998177324121733 0.995280174840507 0.992133654020716 0.988738624749389 0.985095994832775 0.981206716610224 0.977071786768050 0.972692246153409 0.968069179588162 0.963203715682755 0.958097026650084 0.952750328119371 0.947164878950031 0.941341981045545 0.935282979167332 0.928989260748622 0.922462255708321 0.915703436264890 0.908714316750211 0.901496453423459 0.894051444284976 0.886380928890139 0.878486588163234 0.870370144211326 0.862033360138129 0.853478039857879 0.844706027909207 0.835719209269005 0.826519509166304 0.817108892896138 0.807489365633420 0.797662972246815 0.787631797112606 0.777397963928569 0.766963635527843 0.756331013692799 0.745502338968920 0.734479890478659 0.723265985735320 0.711862980456928 0.700273268380098 0.688499281073906 0.676543487753763 0.664408395095284 0.652096547048159 0.639610524650029 0.626952945840348 0.614126465274265 0.601133774136485 0.587977599955151 0.574660706415706 0.561185893174769 0.547555995674006 0.533773884953999 0.519842467468121 0.505764684896401 0.491543513959404 0.477181966232097 0.462683087957718 0.448049959861653 0.433285696965303 0.418393448399959 0.403376397220668 0.388237760220109 0.372980787742464 0.357608763497285 0.342125004373370 0.326532860252634 0.310835713823975 0.295036980397154 0.279140107716656 0.263148575775570 0.247065896629457 0.230895614210219 0.214641304139976 0.198306573544930 0.181895060869242 0.165410435688903 0.148856398525599 0.132236680660593 0.115555043948583 0.0988152806315876 0.0820212131528061 0.0651766939704940 0.0482856053718364 0.0313518592868137 0.0143793971020798 -0.00262781052517255 -0.0196657638533383 -0.0367304342425269 -0.0538177643406945 -0.0709236682697698 -0.0880440318117838 -0.105174712595000 -0.122311540280039 -0.139450316746014 -0.156586816276652 -0.173716785746427 -0.190835944806689 -0.207939986071788 -0.225024575305211 -0.242085351605702 -0.259117927593395 -0.276117889595944 -0.293080797834649 -0.310002186610585 -0.326877564490733 -0.343702414494106 -0.360472194277880 -0.377182336323518 -0.393828248122908 -0.410405312364482 -0.426908887119349 -0.443334306027426 -0.459676878483560 -0.475931889823665 -0.492094601510844 -0.508160251321521 -0.524124053531569 -0.539981199102440 -0.555726855867290 -0.571356168717112 -0.586864259786862 -0.602246228641589 -0.617497152462564 -0.632612086233408 -0.647586062926218 -0.662414093687702 -0.677091168025301 -0.691612253993325 -0.705972298379074 -0.720166226888972 -0.734188944334692 -0.748035334819290 -0.761700261923330 -0.775178568891010 -0.788465078816297 -0.801554594829052 -0.814441900281157 -0.827121758932650 -0.839588915137848 -0.851838094031477 -0.863864001714800 -0.875661325441750 -0.887224733805055 -0.898548876922365 -0.909628386622385 -0.920457876631001 -0.931031942757411 -0.941345163080250 -0.951392098133724 -0.961167291093732 -0.970665267964000 -0.979880537762209 -0.988807592706122 -0.997440908399714 -1.00577494401930 -1.01380414249966 -1.02152293072018 -1.02892571969097 -1.03600690473899 -1.04276086569418 -1.04918196707561 -1.05526455827758 -1.06100297375575 -1.06639153321331 -1.07142454178703 -1.07609629023348 -1.08040105511509 -1.08433309898632 -1.08788667057976 -1.09105600499228 -1.09383532387113 -1.09621883560011 -1.09820073548567 -1.09977520594304 -1.10093641668239 -1.10167852489489 -1.10199567543892 -1.10188200102614 -1.10133162240765 -1.10033864856010 -1.09889717687183 -1.09700129332900 -1.09464507270172 -1.09182257873014 -1.08852786431066 -1.08475497168197 -1.08049793261124 -1.07575076858022 -1.07050749097139 -1.06476210125405 -1.05850859117050 -1.05174094292213 -1.04445312935557 -1.03663911414879 -1.02829285199726 -1.01940828880009 -1.00997936184609 -1]
y = [2 2.26499544506307 2.52345285165919 2.77551012741366 3.02130356526704 3.26096785177083 3.49463607538307 3.72243973476395 3.94450874707147 4.16097145625704 4.37195464136115 4.57758352480892 4.77798178070582 4.97327154313322 5.16357341444407 5.34900647355850 5.52968828425946 5.70573490348834 5.87726088964058 6.04437931086135 6.20720175334112 6.36583832961133 6.52039768683998 6.67098701512728 6.81771205580129 6.96067710971352 7.09998504553457 7.23573730804975 7.36803392645471 7.49697352265110 7.62265331954214 7.74516914932828 7.86461546180284 7.98108533264758 8.09467047172843 8.20546123139099 8.31354661475628 8.41901428401626 8.52195056872954 8.62244047411698 8.72056768935728 8.81641459588266 8.91006227567448 9.00159051955883 9.09107783550219 9.17860145690705 9.26423735090754 9.34806022666506 9.43014354366389 9.51055952000682 9.58937914071082 9.66667216600261 9.74250713961429 9.81695139707904 9.89007107402665 9.96193111447923 10.0325952791468 10.1021261537228 10.1705851571801 10.2380325500660 10.3045274427986 10.3701278039618 10.4348904686013 10.4988711465199 10.5621244305736 10.6247038049668 10.6866616535481 10.7480492681059 10.8089168566642 10.8693135517778 10.9292874188284 10.9888854643200 11.0481536441744 11.1071368720271 11.1658790275228 11.2244229646110 11.2828105198417 11.3410825206610 11.3992787937066 11.4574381731036 11.5155985087602 11.5737966746629 11.6320685771728 11.6904491633205 11.7489724291023 11.8076714277756 11.8665782781543 11.9257241729050 11.9851393868420 12.0448532852234 12.1048943320464 12.1652900983432 12.2260672704765 12.2872516584350 12.3488682041292 12.4109409896870 12.4734932457494 12.5365473597658 12.6001248842901 12.6642465452759 12.7289322503726 12.7942010972203 12.8600713817463 12.9265606064601 12.9936854887492 13.0614619691748 13.1299052197674 13.1990296523224 13.2688489266957 13.3393759590994 13.4106229303974 13.4826012944010 13.5553217861645 13.6287944302809 13.7030285491776 13.7780327714119 13.8538150399664 13.9303826205452 14.0077421098691 14.0858994439713 14.1648599064931 14.2446281369795 14.3252081391748 14.4066032893182 14.4888163444396 14.5718494506550 14.6557041514622 14.7403813960366 14.8258815475266 14.9122043913492 14.9993491434859 15.0873144587782 15.1760984392230 15.2656986422686 15.3561120891100 15.4473352729848 15.5393641674687 15.6321942347710 15.7258204340304 15.8202372296108 15.9154385993964 16.0114180430878 16.1081685904975 16.2056828098453 16.3039528160545 16.4029702790468 16.5027264320383 16.6032120798353 16.7044176071297 16.8063329867944 16.9089477881795 17.0122511854074 17.1162319656689 17.2208785375182 17.3261789391692 17.4321208467907 17.5386915828022 17.6458781241694 17.7536671107000 17.8620448533392 17.9709973424653 18.0805102561854 18.1905689686311 18.3011585582540 18.4122638161214 18.5238692542118 18.6359591137108 18.7485173733063 18.8615277574846 18.9749737448257 19.0888385762990 19.2031052635592 19.3177565972414 19.4327751552571 19.5481433110899 19.6638432420907 19.7798569377739 19.8961662081124 20.0127526918339 20.1295978647159 20.2466830478817 20.3639894160961 20.4814980060606 20.5991897247094 20.7170453575050 20.8350455767337 20.9531709498011 21.0714019475281 21.1897189524464 21.3081022670938 21.4265321223103 21.5449886855333 21.6634520690937 21.7819023385110 21.9003195207895 22.0186836127132 22.1369745891423 22.2551724113081 22.3732570351088 22.4912084194057 22.6090065343178 22.7266313695183 22.8440629425299 22.9612813070203 23.0782665610982 23.1949988556084 23.3114584024278 23.4276254827613 23.5434804554365 23.6590037652004 23.7741759510141 23.8889776543494 24.0033896274833 24.1173927417946 24.2309679960590 24.3440965247448 24.4567596063089 24.5689386714917 24.6806153116135 24.7917712868696 24.9023885346262 25.0124491777157 25.1219355327329 25.2308301183300 25.3391156635127 25.4467751159356 25.5537916501978 25.6601486761387 25.7658298471334 25.8708190683886 25.9751005052380 26.0786585914379 26.1814780374631 26.2835438388023 26.3848412842538 26.4853559642211 26.5850737790085 26.6839809471169 26.7820640135392 26.8793098580560 26.9757057035313 27.0712391242082 27.1658980540041 27.2596707948069 27.3525460247703 27.4445128066094 27.5355605958967 27.6256792493570 27.7148590331637 27.8030906312344 27.8903651535260 27.9766741443309 28.0620095905721 28.1463639300994 28.2297300599846 28.3121013448172 28.3934716250003 28.4738352250458 28.5531869618704 28.6315221530909 28.7088366253202 28.7851267224627 28.8603893140098 28.9346218033358 29.0078221359933 29.0799888080092 29.1511208741798 29.2212179563668 29.2902802517928 29.3583085413370 29.4253041978307 29.4912691943530 29.5562061125265 29.6201181508128 29.6830091328082 29.7448835155393 29.8057463977587 29.8656035282405 29.9244613140760 29.9823268289694 30.0392078215333 30.0951127235842 30.1500506584387 30.2040314492083 30.2570656270958 30.3091644396903 30.3603398592634 30.4106045910644 30.4599720816159 30.5084565270100 30.5560728812031 30.6028368643122 30.6487649709102 30.6938744783217 30.7381834549183 30.7817107684148 30.8244760941642 30.8664999234537 30.9078035718003 30.9484091872463 30.9883397586550 31.0276191240064 31.0662719786928 31.1043238838141 31.1418012744739 31.1787314680751 31.2151426726150 31.2510639949816 31.2865254492487 31.3215579649719 31.3561933954840 31.3904645261906 31.4244050828661 31.4580497399487 31.4914341288367 31.5245948461837 31.5575694621942 31.5903965289195 31.6231155885532 31.6557671817267 31.6883928558052 31.7210351731827 31.7537377195783 31.7865451123314 31.8195030086975 31.8526581141437 31.8860581906445 31.9197520649774 31.9537896370183 31.9882218880374 32.0231008889946 32.0584798088355 32.0944129227864 32.1309556206506 32.1681644151037 32.2060969499891 32.2448120086139 32.2843695220444 32.3248305774017 32.3662574261575 32.4087134924294 32.4522633812768 32.4969728869964 32.5429090014181 32.5901399222001 32.6387350611250 32.6887650523952 32.7403017609286 32.7934182906543 32.8481889928080 32.9046894742278 32.9629966056499 33.0231885300040 33.0853446707091 33.1495457399690 33.2158737470682 33.2844120066671 33.3552451470980 33.4284591186606 33.5041412019175 33.5823800159901 33.6632655268539 33.7468890556344 33.8333432869025 33.9227222769705 34.0151214621873 34.1106376672341 34.2093691134204 34.3114154269792 34.4168776473628 34.5258582355384 34.6384610822839 34.7547915164830 34.8749563134217 34.9990637030830 35.1272233784432 35.2595465037671 35.3961457229040 35.5371351675831 35.6826304657089 35.8327487496574 35.9876086645714 36.1473303766559 36.3120355814743 36.4818475122433 36.6568909481293 36.8372922225435 37.0231792314376 37.2146814415997 37.4119298989495 37.6150572368345 37.8241976843249 38.0394870745098 38.2610628527928 38.4890640851872 38.7236314666120 38.9649073291876 39.2130356505310 39.4681620620517 39.7304338572476 40]
However the rectangle doesn't orient itself exactly towards the curve in question, it still has a offset.Any help is appreciated. Thanks.
Hi i'm posting the solution to the question here. Thanks to anyone who took time to take a look at it.
for k=2:length(x)
%%%Plot road
rl=-2; rr=0; w=4; l=100;
yroad = 0:l;
xroad = repmat(rl+w/2,l+1);
plot(xroad, yroad, 'w--','LineWidth',1.5);
hold on;
rectangle('Position',[rl,rr,w,l],'FaceColor',[0 0 0 0.9]);
axis([-4 4 0 50]);
hold on;
%%%%%
set(gca,'children',flipud(get(gca,'children')))
%%%time annotation
str = strcat('t=',string(t));
% annotation('textbox',[0.8 0.8 .5 .5],'String',str,'FitBoxToText','on');
text(1,47,str,'Color','w')
ratio = diff(get(gca, 'YLim'))/diff(get(gca, 'XLim'));
phi = atan2(y(k) - y(k - 1), (x(k) - x(k - 1))*ratio);
[x_rect_rot, y_rect_rot]=get_rectangle(phi, x(k), y(k));
plot(polyshape(x_rect_rot, y_rect_rot),'FaceColor','c','FaceAlpha',0.85);
hold on;
plot(x(1:k), y(1:k));
hold on;
drawnow;
end
function[xa,ya] =get_rectangle(phi,xc,yc,varargin)
if length(varargin)<2
h = 5;
w = 3;
else
h = varargin{4};
w = varargin{5};
end
x_rect = [-h, h, h, -h]/2;
y_rect = [-w, -w, w, w]/2;
% Consider aspect ratio of the axis
ratio = diff(get(gca, 'YLim'))/diff(get(gca, 'XLim'));
% Calculate rotated rectangle
x_rect_rot = x_rect*cos(phi) - y_rect*sin(phi);
y_rect_rot = x_rect*sin(phi) + y_rect*cos(phi);
% Incorporate ratio
x_rect_rot = x_rect_rot/ratio;
% Calculate offset
xa = x_rect_rot + xc;
ya = y_rect_rot + yc;
end

Quiver list and labeling vectors of my inputs u,d, and r

How do I label each vector of each input component, say u$_1$..., d$_1$..., on my graph at each vector's respective starting point. I want to see if there is a clustering of certain vectors like u$_30$-u$_50$ are all near each other, for example. Here is my code:
fx = [1.01, 1.0165376460248143, 1.016585505356985,...
1.0166786731186357, 1.0166445649045002, 1.01684528204491,...
1.0168363943981442, 1.0169505828006045, 1.0169903647693619,...
1.0170588800755562, 1.0170214556321182, 1.0171007103163394,...
1.0170611565299144, 1.0171737504115423, 1.0171325089936156,...
1.0173884633568437, 1.0173821295549914, 1.017540453473392,...
1.0176091468862674, 1.0177647297690604, 1.017711866139699,...
1.0177536635811828, 1.0178254876275734, 1.0173994306983212,...
1.0200331803664529, 1.0232411092365432, 1.0232773133875106,...
1.023383936276914, 1.0233275057530007, 1.023510835824228,...
1.0234461433923472, 1.023507118352957, 1.0237210297124908,...
1.0236390252916325, 1.0237007559499636, 1.0239084387662698,...
1.0238131746118633, 1.024266374303865, 1.024212732428539,...
1.02440393427416, 1.0245390401237269, 1.0252178000353167,...
1.0252021019242434, 1.0275875709904758, 1.0275871039342042];
fy = [0.99, 0.99, 0.9899194500620327, 0.9897134368447225,...
0.9899339650105077, 0.9895259027418399, 0.9898115223446341,...
0.9896762515189842, 0.9896129792784014, 0.9894766621994305,...
0.9896189382715079, 0.9894614440540032, 0.9896292673356496,...
0.9894095770062209, 0.989655005387203, 0.9892019096930893,...
0.9894189058876284, 0.9892732425545386, 0.9891916768216495,...
0.9889512723219249, 0.9892071461243063, 0.9891515372181835,...
0.9890346980816267, 0.9901802532401042, 0.9892771992437573,...
0.9881487558751526, 0.9880037699743045, 0.9875669935217211,...
0.9878502051001951, 0.9872010568874899, 0.9875329139453003,...
0.9873775054641964, 0.9868251990627905, 0.9871082986923524,...
0.9869819983991632, 0.9865548473263468, 0.9867867860622922,...
0.9859765136441385, 0.9861731333993694, 0.9859212446482857,...
0.9857475603282838, 0.9848759880952044, 0.9850648602644492,...
0.9821891156159342, 0.9822254068452594];
fz =[0.01, -0.0014683388934621459, -0.0028093690242636917,...
-0.006255424514110392, -0.002405171080788649, -0.009167776104980133,...
0.0003750210183572269, -0.001823375333180016, -0.002906415137850454,...
-0.005227263048381278, -0.0028662319950483552, -0.0055329993182467365,...
-0.0027458980004112996, -0.00644276568444028, -0.00226410433801184,...
-0.009832266892691467, 0.0012478354917326469, -0.001163969711179093,...
-0.0026270200357900887, -0.006946260715800828, -0.00188587841967576,...
-0.002880843788516535, -0.0049636661241180685, 0.015586949435911355,...
0.010368914010693711, -0.0010649331940053245, -0.002328942248654949,...
-0.006634620630021168, -0.0020052485893380344, -0.008543368794125199,...
-0.00044976575279103564, -0.0019790036016751333, -0.008330963679008077,...
-0.0006481277669472506, -0.0020539789179887767, -0.0075781311330381336,...
-0.001294365366809558, -0.011629381859506432, 0.003447063734076782,...
0.0011256038145771368, -0.0008637305140054806, -0.012865086502170518,...
0.005283762238371167, -0.016926299226379265, 0.011993515880473204];
x = [1.01, 1.0165376460248143, 1.016585505356985, 1.0166786731186357,...
1.0166445649045002, 1.01684528204491, 1.0168363943981442,...
1.0169505828006045, 1.0169903647693619, 1.0170588800755562,...
1.0170214556321182, 1.0171007103163394, 1.0170611565299144,...
1.0171737504115423, 1.0171325089936156, 1.0173884633568437,...
1.0173821295549914, 1.017540453473392, 1.0176091468862674,...
1.0177647297690604, 1.017711866139699, 1.0177536635811828,...
1.0178254876275734, 1.0173994306983212, 1.0200331803664529,...
1.0232411092365432, 1.0232773133875106, 1.023383936276914,...
1.0233275057530007, 1.023510835824228, 1.0234461433923472,...
1.023507118352957, 1.0237210297124908, 1.0236390252916325,...
1.0237007559499636, 1.0239084387662698, 1.0238131746118633,...
1.024266374303865, 1.024212732428539, 1.02440393427416,...
1.0245390401237269, 1.0252178000353167, 1.0252021019242434,...
1.0275875709904758, 1.0275871039342042];
y = [0.99, 0.99, 0.9899194500620327, 0.9897134368447225,...
0.9899339650105077, 0.9895259027418399, 0.9898115223446341,...
0.9896762515189842, 0.9896129792784014, 0.9894766621994305,...
0.9896189382715079, 0.9894614440540032, 0.9896292673356496,...
0.9894095770062209, 0.989655005387203, 0.9892019096930893,...
0.9894189058876284, 0.9892732425545386, 0.9891916768216495,...
0.9889512723219249, 0.9892071461243063, 0.9891515372181835,...
0.9890346980816267, 0.9901802532401042, 0.9892771992437573,...
0.9881487558751526, 0.9880037699743045, 0.9875669935217211,...
0.9878502051001951, 0.9872010568874899, 0.9875329139453003,...
0.9873775054641964, 0.9868251990627905, 0.9871082986923524,...
0.9869819983991632, 0.9865548473263468, 0.9867867860622922,...
0.9859765136441385, 0.9861731333993694, 0.9859212446482857,...
0.9857475603282838, 0.9848759880952044, 0.9850648602644492,...
0.9821891156159342, 0.9822254068452594];
z =[0.01, -0.0014683388934621459, -0.0028093690242636917,...
-0.006255424514110392, -0.002405171080788649, -0.009167776104980133,...
0.0003750210183572269, -0.001823375333180016, -0.002906415137850454,...
-0.005227263048381278, -0.0028662319950483552, -0.0055329993182467365,...
-0.0027458980004112996, -0.00644276568444028, -0.00226410433801184,...
-0.009832266892691467, 0.0012478354917326469, -0.001163969711179093,...
-0.0026270200357900887, -0.006946260715800828, -0.00188587841967576,...
-0.002880843788516535, -0.0049636661241180685, 0.015586949435911355,...
0.010368914010693711, -0.0010649331940053245, -0.002328942248654949,...
-0.006634620630021168, -0.0020052485893380344, -0.008543368794125199,...
-0.00044976575279103564, -0.0019790036016751333, -0.008330963679008077,...
-0.0006481277669472506, -0.0020539789179887767, -0.0075781311330381336,...
-0.001294365366809558, -0.011629381859506432, 0.003447063734076782,...
0.0011256038145771368, -0.0008637305140054806, -0.012865086502170518,...
0.005283762238371167, -0.016926299226379265, 0.011993515880473204];
figure
q = quiver3(fx,fy,fz,x,y,z)
The problem is that I want to label the starting point of each vector:
You can use text:
q = quiver3(fx,fy,fz,x,y,z)
text(fx,fy,fz,num2str((1:numel(fx)).'))
The first 3 inputs are the coordinates of the label and the next input is a list (column character array or a cell-array) of the labels. I don't understand how your labeling is working (i.e. what is u$_1$ or d$_1$), so I just numbered the vectors from 1 to 45.

Plot a V-shape function given its points

I have the following matrix which rows are points sampled from a function
f = [ -3.7850 -11.5240
-3.7753 -11.4822
-3.7680 -11.5427
-3.7592 -11.5607
-3.7576 -11.5461
-3.7454 -11.5887
-3.7386 -11.4070
-3.7358 -11.4450
-3.7289 -11.5511
-3.7254 -11.3713
-3.7122 -11.4515
-3.6820 -11.5582
-3.6758 -11.5946
-3.6732 -11.5823
-3.6679 -11.6365
-3.6487 -11.3525
-3.6424 -11.2745
-3.6322 -11.3478
-3.6235 -11.6379
-3.6159 -11.6308
-3.5619 -11.1980
-3.5550 -11.2284
-3.5544 -11.5925
-3.5147 -11.6578
-3.5041 -11.6756
-3.4860 -11.1550
-3.4654 -11.6341
-3.4550 -11.1329
-3.3802 -11.6701
-3.3691 -11.1083
-3.3541 -11.0790
-3.3485 -11.5887
-3.3006 -11.6384
-3.2481 -11.5570
-3.2459 -11.0268
-3.2441 -10.9314
-3.2301 -11.5225
-3.2270 -10.8832
-3.1543 -10.8612
-3.1528 -11.5490
-3.1167 -11.5021
-3.1102 -10.8255
-3.0645 -11.5618
-2.9967 -11.5420
-2.9898 -10.8136
-2.9645 -10.7107
-2.9211 -11.4197
-2.9175 -10.6389
-2.8558 -10.6015
-2.8327 -11.5108
-2.7768 -11.4501
-2.7392 -10.5492
-2.7217 -11.4230
-2.6988 -10.4724
-2.6235 -11.3226
-2.6196 -11.3806
-2.5772 -10.4518
-2.5458 -10.4317
-2.5014 -10.3176
-2.4832 -11.3822
-2.4778 -10.2456
-2.4029 -11.2907
-2.3723 -10.3002
-2.3590 -11.2911
-2.3491 -10.2110
-2.2756 -11.2318
-2.2554 -10.1204
-2.2542 -10.1411
-2.2181 -11.2300
-2.1982 -9.9584
-2.1645 -9.7938
-2.1541 -11.1682
-2.1476 -9.8235
-2.1451 -9.9205
-2.1280 -10.0064
-2.1269 -9.8947
-2.0898 -9.7926
-2.0781 -11.1293
-1.9985 -11.0985
-1.9249 -11.0443
-1.8220 -11.0419
-1.7359 -11.0043
-1.6924 -10.9775
-1.6049 -10.9579
-1.5275 -10.9339
-1.4757 -10.9113
-1.4122 -10.8854
-1.3245 -10.8908
-1.2936 -10.7893
-1.2091 -10.8121
-1.1575 -10.8064
-1.1237 -10.7105
-1.0571 -10.7724
-1.0217 -10.7096
-0.9717 -10.6984
-0.9447 -10.7103
-0.9120 -10.6687
-0.8908 -10.6670]
Plotting by plot(f(:,1),f(:,2),'+') it is clear that the function has a V-shape. However, I need to plot it continuously, but doing plot(f(:,1),f(:,2)) results in a zig-zag function. How can I plot the points as I want to? (beside sorting them manually)
You could try rotating your data, sorting it and rotating it back. e.g:
theta = -1;
R = [cos(theta) -sin(theta);sin(theta) cos(theta)];
f2 = f*R;
f3 = sortrows(f2);
f4 = f3*R';
plot(f4(:,1),f4(:,2),'-',f(:,1),f(:,2),'+')
You can tweak theta to change the angle, which affects the sort order, I just took a guess that -1 is about right.

find corresponding peaks in matlab with 95% confidence interval

Suppose that we have following array:
0.196238259763928
0.0886250228175519
0.417543614272817
0.182403230538167
0.136500793051860
0.389922187581014
0.0344012946153299
0.381603315802419
0.0997542838649466
0.274807632628596
0.601652859233616
0.209431489000677
0.396925294300794
0.0351587496999554
0.177321874549738
0.369200511917405
0.287108838007101
0.477076452316346
0.127558716868438
0.792431584110476
0.0459982776925879
0.612598437936600
0.228340227044324
0.190267907472804
0.564751537228850
0.00269368929400299
0.940538666131177
0.101588565140294
0.426175626669060
0.600215481734847
0.127859067121782
0.985881201195063
0.0945679498528667
0.950077461673118
0.415212985598547
0.467423473845033
1.24336273213410
0.0848695928658021
1.84522775800633
0.289288949281834
1.38792131632743
1.73186592736729
0.554254947026916
3.46075557122590
0.0872957577705428
4.93259798197976
2.03544238985229
3.71059303259615
8.47095716918618
0.422940369071662
25.2287636895831
4.14535369056670
63.7312173032838
152.080907190007
1422.19492782494
832.134744027851
0.0220089962114756
60.8238733887811
7.71053463387430
10.4151913932115
11.3141744831953
0.988978595613829
8.65598040591953
0.219820300144944
3.92785491164888
2.28370963778411
1.60232807621444
2.51086405960291
0.0181622519984990
2.27469230188760
0.487809730727909
0.961063613990814
1.90435488292485
0.515640996120482
1.25933693517960
0.0953200831348589
1.52851575480462
0.582109930768162
0.933543409438383
0.717947488528521
0.0445235241119612
1.21157308704582
0.0942421028083462
0.536069075206508
0.821400666720535
0.308956823975938
1.28706199713640
0.0339217632187507
1.19575886464231
0.0853733920496230
0.736744959694641
0.635218502184121
0.262305581223588
0.986899895695809
0.0398800891449550
0.758792061180657
0.134279188964854
0.442531129290843
0.542782326712391
0.377221037448628
0.704787750202814
0.224180325609783
0.998785634315287
0.408055416702400
0.329684702125840
0.522384453408780
0.154542718256493
0.602294251721841
0.240357912028348
0.359040779285709
0.525224294805813
0.427539247203335
0.624034405807298
0.298184846094056
0.498659616687732
0.0962076792277457
0.430092706132805
0.656212420735658
0.278310520474744
0.866037361133916
0.184971060800812
0.481149730712771
0.624405636807668
0.382388147099945
0.435350646037440
0.216499523971397
1.22960953802959
0.330841706900755
0.891793067878849
0.628241046456751
0.278687691121678
1.06358076764171
0.365652714373067
1.34921178081181
0.652888708375276
0.861138633227739
1.02878577330537
0.591174450919664
1.93594290806582
0.497631035062465
1.14486512201656
0.978067581547298
0.948931658572253
2.01004088022982
0.917415940349743
2.24124811810385
1.42691656876436
2.15636037453584
1.92812357585099
1.12786835077183
4.81721425534142
1.70055431306602
4.87939454466131
3.90293284926105
5.16542230018432
10.5783535493504
1.74023535081791
27.0572221453758
7.78813114379733
69.2528169436690
167.769806437531
1490.03057130613
869.247150795648
3.27543244752518
62.3527480644562
9.74192115073051
13.6074209231800
10.5686495478844
7.70239986387120
9.62850426896699
9.85304975304259
7.09026325332085
12.8782040428502
16.3163128995995
7.00070066635845
74.1532966917877
4.80506505312457
1042.52337489620
1510.37374385290
118.514435606795
80.7915675273571
2.96352221859211
27.7825124315786
1.55102367292252
8.66382951478539
5.02910503820560
1.25219344189599
7.72195587189507
0.356973215117373
6.06702456628919
1.01953617014621
2.76489896186652
3.35353608882459
0.793376336025486
4.90341095941571
0.00742857354167949
5.07665716731356
1.16863474789604
4.47635486149688
4.33050121578669
2.42974020115261
9.79494608790444
0.0568839453395247
22.9153086380666
4.48791386399205
59.6962194708933
97.8636220152072
1119.97978883924
806.144299041605
7.33252581243942
57.0699524267842
0.900104994068117
15.2791339483160
3.31266162202546
3.20809490583211
5.36617545130941
0.648122925703121
3.90480316969632
0.0338850542128927
2.58828964019220
0.543604662856673
1.16385064506181
1.01835324272839
0.172915006573539
1.55998411282069
0.00221570175453666
1.14803074836796
0.0769335878967426
0.421762398811163
0.468260146832541
0.203765185125597
0.467641715366303
0.00142988680149041
0.698088976126660
0.0413316717103625
0.190548157914037
0.504713663418641
0.325697764871308
0.375910057283262
0.123307135682793
0.331115262928959
0.00263961045860704
0.204555648718379
0.139008751575803
0.182936666944843
0.154943314848474
0.0840483576044629
0.293075999812128
0.00306911699543199
0.272993318570981
0.0864711337990886
0.280495615619829
0.0910123210559269
0.148399626645134
0.141945002415500
0.0512001531781583
0.0295283557338525
In MATLAB it is very easy to find peaks using findpeaks, like so:
[pxx_peaks,location] = findpeaks(Pxx);
If we plot pxx_peaks, we get
plot(pxx_peaks)
Of course, besides these peaks, there are smaller peaks which are not shown on the picture, but my goal is to find all peaks which are 95-96% above all other peaks.
I have tried like this:
>> average = mean(pxx_peaks);
>> stand = std(pxx_peaks);
>> final_peaks = pxx_peaks( pxx_peaks > average + 3*stand );
The result of this is
>> final_peaks
final_peaks =
1.0e+03 *
1.4222
1.4900
1.5104
1.1200
but how to return their corresponding locations? I want to write it as one m-file, so please help me
EDIT
also please help me in this question: can I parameterize the confidence interval? For instance instead of 95%, I want to find peaks that are 60% above then other peaks, is it possible?
Note that 3σ ≈ 99.73%
As for your first question, it's easy, you just have to keep track of the locations in the same way as you do for the peaks:
inds = pxx_peaks > mean(pxx_peaks) + 3*std(pxx_peaks);
final_peaks = pxx_peaks(inds);
final_locations = location(inds);
plot(Pxx), hold on
plot(final_locations, final_peaks, 'r.')
As for your second question, that's a little more complicated. If you want to formulate it like you say, you'll have to convert a desired percentage to the correct number of σ. That involves an integration of the standard normal, and a root finding:
%// Convert confidence interval percentage to number-of-sigmas
F = #(P) fzero(#(sig) quadgk(#(x) exp(-x.^2/2),-sig,+sig)/sqrt(2*pi) - P/100, 1);
% // Repeat with the desired percentage
inds = pxx_peaks > mean(pxx_peaks) + F(63)*std(pxx_peaks); %// 63%
final_peaks = pxx_peaks(inds);
final_locations = location(inds);
plot(final_locations, final_peaks, 'r.')