Parse text to show 3D triangles - matlab
(Using Octacve) I have a text file with triangle vertices defined in this way:
((x11, y11, z11), (x12, y12, z12), (x13, y13, z13))((x21, y21, z21), (x22, y22, z22), (x23, y23, z23))...((xn1, yn1, zn1), (xn2, yn2, zn2), (xn3, yn3, zn3))
This is a list of triangles in 3D space, with every triangle defined as ((xn1, yn1, zn1)(xn2, yn2, zn2)(xn3, yn3, zn3)).
How can I import this file in Octave in order to see the generated mesh? I know I can use trimesh, but I'm not be able to parse this file in order to retrieve point coordinates.
EDIT: This is a real file with some triangle:
((-0.780869, -1.56174, 4.68521), (-0.776988, -1.08169, 4.81936), (-0.776988, -2.02627, 4.5045))((-0.776988, -1.08169, 4.81936), (-0.765386, -0.590883, 4.90561), (-0.776988, -2.02627, 4.5045))((-0.776988, -2.02627, 4.5045), (-0.765386, -0.590883, 4.90561), (-0.765386, -2.47066, 4.27902))((-0.765386, -0.590883, 4.90561), (-0.746177, -0.0942074, 4.94311), (-0.765386, -2.47066, 4.27902))((-0.765386, -2.47066, 4.27902), (-0.746177, -0.0942074, 4.94311), (-0.746177, -2.8905, 4.01101))((-0.746177, -0.0942074, 4.94311), (-0.719552, 0.403404, 4.93148), (-0.746177, -2.8905, 4.01101))((-0.746177, -2.8905, 4.01101), (-0.719552, 0.403404, 4.93148), (-0.719552, -3.28161, 3.70314))((-0.719552, 0.403404, 4.93148), (-0.685776, 0.897006, 4.87084), (-0.719552, -3.28161, 3.70314))((-0.719552, -3.28161, 3.70314), (-0.685776, 0.897006, 4.87084), (-0.685776, -3.64011, 3.35847))((-0.685776, 0.897006, 4.87084), (-0.645184, 1.38169, 4.76179), (-0.685776, -3.64011, 3.35847))((-0.685776, -3.64011, 3.35847), (-0.645184, 1.38169, 4.76179), (-0.645184, -3.96243, 2.98042))((-0.645184, 1.38169, 4.76179), (-0.59818, 1.85265, 4.60542), (-0.645184, -3.96243, 2.98042))((-0.645184, -3.96243, 2.98042), (-0.59818, 1.85265, 4.60542), (-0.59818, -4.24537, 2.57274))((-0.59818, 1.85265, 4.60542), (-0.545231, 2.30519, 4.40327), (-0.59818, -4.24537, 2.57274))((-0.59818, -4.24537, 2.57274), (-0.545231, 2.30519, 4.40327), (-0.545231, -4.48612, 2.1395))((-0.545231, 2.30519, 4.40327), (-0.486864, 2.73482, 4.15737), (-0.545231, -4.48612, 2.1395))((-0.545231, -4.48612, 2.1395), (-0.486864, 2.73482, 4.15737), (-0.486864, -4.68228, 1.685))((-0.486864, 2.73482, 4.15737), (-0.423657, 3.13728, 3.87014), (-0.486864, -4.68228, 1.685))((-0.486864, -4.68228, 1.685), (-0.423657, 3.13728, 3.87014), (-0.423657, -4.83191, 1.21375))((-0.423657, 3.13728, 3.87014), (-0.356241, 3.50855, 3.54445), (-0.423657, -4.83191, 1.21375))((-0.423657, -4.83191, 1.21375), (-0.356241, 3.50855, 3.54445), (-0.356241, -4.93351, 0.730433))((-0.356241, 3.50855, 3.54445), (-0.285283, 3.84496, 3.18354), (-0.356241, -4.93351, 0.730433))((-0.356241, -4.93351, 0.730433), (-0.285283, 3.84496, 3.18354), (-0.285283, -4.98609, 0.23986))((-0.285283, 3.84496, 3.18354), (-0.211491, 4.14315, 2.79099), (-0.285283, -4.98609, 0.23986))((-0.285283, -4.98609, 0.23986), (-0.211491, 4.14315, 2.79099), (-0.211491, -4.98911, -0.253097))((-0.211491, 4.14315, 2.79099), (-0.135596, 4.40016, 2.3707), (-0.211491, -4.98911, -0.253097))((-0.211491, -4.98911, -0.253097), (-0.135596, 4.40016, 2.3707), (-0.135596, -4.94255, -0.743539))((-0.135596, 4.40016, 2.3707), (-0.0583544, 4.61344, 1.92684), (-0.135596, -4.94255, -0.743539))((-0.135596, -4.94255, -0.743539), (-0.0583544, 4.61344, 1.92684), (-0.0583544, -4.84686, -1.22659))
(This was tested with MATLAB, but should work fine in Octave too)
To parse the file you may use the following function:
function A = fparse_triangle(fname)
f = fopen(fname, 'r');
A = reshape(fscanf(f, '((%f, %f, %f)(%f, %f, %f)(%f, %f, %f))'),3,3,[]);
fclose(f);
end
The result will be a 3×3×n matrix, on first index having coordinates of vertices (X, Y, Z), on second index having vertices of a triangle (1st, 2nd, 3rd), and on third index having triangles.
Later edit
This alternative will take in account vertices that are separated by commas, as in the recently added example:
function A = fparse_triangle_alt(fname)
f = fopen(fname, 'r');
A = reshape(fscanf(f, '((%f, %f, %f), (%f, %f, %f), (%f, %f, %f))'),3,3,[]);
fclose(f);
end
NB
Mind that from this to a trimesh call there's a bit more processing involved. Let me know if you'd need help with that.
Related
Using interp2 - The grid must be created from grid vectors which are strictly monotonically increasing
I am using MATLAB_R2016b. I have data of this format Temperature = [310:10:800]; Pressure = [0.1 0 1.0 10.0 100.0 1000.0]; Cv = ... [ 73.6400 25.3290 73.5920 73.1260 69.4500 61.8600 72.8060 25.3810 72.7640 72.3450 68.9780 61.7040 71.9230 25.4380 71.8850 71.5070 68.4230 61.3140 71.0060 25.4990 70.9710 70.6290 67.8040 60.8160 70.0680 25.5640 70.0360 69.7270 67.1400 60.2840 69.1220 25.6340 69.0940 68.8140 66.4460 59.7550 68.1800 25.7070 68.1540 67.9000 65.7350 59.2500 27.6640 25.7840 67.2240 66.9940 65.0150 58.7780 27.3630 25.8640 66.3120 66.1040 64.2950 58.3390 27.1700 25.9480 65.4220 65.2330 63.5820 57.9340 27.0440 26.0340 64.5570 64.3850 62.8790 57.5600 26.9660 26.1230 63.7210 63.5640 62.1900 57.2130 26.9240 26.2150 62.9130 62.7700 61.5170 56.8890 26.9110 26.3090 62.1360 62.0050 60.8620 56.5870 26.9200 26.4050 61.3890 61.2690 60.2250 56.3020 26.9460 26.5030 33.1250 60.5620 59.6080 56.0320 26.9870 26.6030 31.8460 59.8850 59.0090 55.7750 27.0390 26.7050 31.0570 59.2360 58.4290 55.5290 27.1010 26.8080 30.5000 58.6170 57.8680 55.2920 27.1700 26.9120 30.0840 58.0280 57.3240 55.0630 27.2460 27.0170 29.7670 57.4700 56.7980 54.8410 27.3280 27.1240 29.5260 56.9450 56.2900 54.6250 27.4140 27.2320 29.3430 56.4560 55.7970 54.4150 27.5040 27.3410 29.2080 56.0070 55.3210 54.2090 27.5980 27.4500 29.1110 55.6040 54.8600 54.0080 27.6940 27.5610 29.0460 55.2610 54.4150 53.8100 27.7930 27.6720 29.0060 54.9970 53.9840 53.6160 27.8950 27.7840 28.9870 54.8470 53.5670 53.4260 27.9980 27.8970 28.9870 51.7540 53.1650 53.2390 28.1030 28.0110 29.0020 47.2710 52.7760 53.0550 28.2100 28.1250 29.0290 44.3160 52.4010 52.8750 28.3180 28.2400 29.0670 42.1390 52.0390 52.6980 28.4270 28.3550 29.1150 40.4520 51.6910 52.5230 28.5380 28.4710 29.1710 39.1070 51.3570 52.3520 28.6500 28.5880 29.2340 38.0170 51.0350 52.1840 28.7630 28.7060 29.3040 37.1240 50.7260 52.0200 28.8770 28.8240 29.3780 36.3870 50.4300 51.8580 28.9920 28.9420 29.4580 35.7750 50.1460 51.7000 29.1080 29.0610 29.5420 35.2640 49.8730 51.5440 29.2250 29.1810 29.6290 34.8380 49.6100 51.3930 29.3420 29.3010 29.7200 34.4810 49.3570 51.2440 29.4610 29.4220 29.8150 34.1820 49.1120 51.0990 29.5800 29.5440 29.9120 33.9330 48.8720 50.9570 29.6990 29.6660 30.0110 33.7250 48.6360 50.8190 29.8200 29.7880 30.1130 33.5540 48.4000 50.6830 29.9410 29.9110 30.2170 33.4130 48.1630 50.5520 30.0630 30.0340 30.3230 33.3000 47.9210 50.4230 30.1850 30.1580 30.4310 33.2100 47.6720 50.2990 30.3080 30.2820 30.5400 33.1400 47.4140 50.1770 30.4310 30.4070 30.6510 33.0890 47.1430 50.0590]; When I try to query a new [temperature, pressure] pair, for example [0.2, 341] by doing this interp2(Temperature, Pressure, Cv, 0.2, 341) I get the following error: Error using griddedInterpolant The grid vectors must be strictly monotonically increasing. Error in interp2>makegriddedinterp (line 229) F = griddedInterpolant(varargin{:}); Error in interp2 (line 129) F = makegriddedinterp({X, Y}, V, method,extrap); What am I doing wrong? And how can I get the desired result?
You need to have the same number of points in Temperature and Pressure as you do in Cv. You can generate these points using meshgrid. [Temp, Pres] = meshgrid(Temperature, Pressure) % Temp and Pres are both 6x50 matrices However, you still have an issue. Temperature and Pressure must be monotonically increasing, as the error message states. This means you can't have a pressure value go down, which it does. You must change the second value in the Pressure array, or for instance you may want to swap columns 1 and 2 of the Pressure and Cv arrays Pressure = [0.1, 0, 1, 10, 100, 1000]; % original Pressure = Pressure([2, 1, 3:end]); % swap columns 1 and 2, Pressure = [0,0.1,1,10,...] Cv = [...]; % All of your data Cv = Cv(:, [2, 1, 3:end]) % Swap columns 1 and 2 Now you can do your lookup. Note you also had the temperature and pressure values the wrong way around, they must be the same order for inputs 1/2 and inputs 4/5. [Temp, Pres] = meshgrid(Temperature, Pressure); out = interp2(Temp, Pres, Cv.', 341, 0.2) % not (..., 0.2, 341) as must be same order >> out = 30.5468 The only consideration you might want to give is that you're using linear interpolation with interp2, but your pressure data is logarithmic. Check your results are sensible.
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.
3D transformation of matrix in Matlab
I want a Matlab's solution to the 3D-transformation/rotation of a matrix which rotate the given vector in such a way that initial points are changed to some angle but final points are same. I have a P vector to operate this scenario. What would be the suggestions to transform this matrix into further versions (more projectiles from one parent projectile)such that it changes its degree of starting direction of projectile and having constant final position to hit the target.! I'm not very much accurate in the drawing as this in 2D but I want the same concept in 3D, here the target is the final place of projectile, which is suppoesed same iin whole scenerio, but the starting points are supposing trasformed to some angle/direction derived from parent projectile. I hope i'm clearing my case. P vector: P = -21.8318 19.2251 -16.0000 -21.7386 19.1620 -15.9640 -21.6455 19.0988 -15.9279 -21.5527 19.0357 -15.8918 -21.4600 18.9727 -15.8556 -21.3675 18.9096 -15.8194 -21.2752 18.8466 -15.7831 -21.1831 18.7836 -15.7468 -21.0911 18.7206 -15.7105 -20.9993 18.6577 -15.6741 -20.9078 18.5947 -15.6377 -20.8163 18.5318 -15.6012 -20.7251 18.4689 -15.5647 -20.6340 18.4061 -15.5281 -20.5432 18.3432 -15.4915 -20.4524 18.2804 -15.4548 -20.3619 18.2176 -15.4181 -20.2715 18.1548 -15.3814 -20.1813 18.0921 -15.3446 -20.0913 18.0293 -15.3078 -20.0015 17.9666 -15.2709 -19.9118 17.9039 -15.2340 -19.8223 17.8412 -15.1970 -19.7329 17.7786 -15.1601 -19.6438 17.7160 -15.1230 -19.5547 17.6534 -15.0860 -19.4659 17.5908 -15.0489 -19.3772 17.5282 -15.0117 -19.2887 17.4656 -14.9745 -19.2004 17.4031 -14.9373 -19.1122 17.3406 -14.9001 -19.0241 17.2781 -14.8628 -18.9363 17.2156 -14.8254 -18.8486 17.1532 -14.7881 -18.7610 17.0907 -14.7507 -18.6736 17.0283 -14.7132 -18.5864 16.9659 -14.6758 -18.4994 16.9035 -14.6383 -18.4124 16.8412 -14.6007 -18.3257 16.7788 -14.5632 -18.2391 16.7165 -14.5255 -18.1526 16.6542 -14.4879 -18.0663 16.5919 -14.4502 -17.9802 16.5296 -14.4125 -17.8942 16.4673 -14.3748 -17.8084 16.4051 -14.3370 -17.7227 16.3429 -14.2992 -17.6372 16.2807 -14.2614 -17.5518 16.2185 -14.2235 -17.4665 16.1563 -14.1856 -17.3815 16.0941 -14.1477 -17.2965 16.0320 -14.1097 -17.2117 15.9698 -14.0718 -17.1271 15.9077 -14.0338 -17.0426 15.8456 -13.9957 -16.9582 15.7835 -13.9576 -16.8740 15.7214 -13.9196 -16.7899 15.6594 -13.8814 -16.7060 15.5973 -13.8433 -16.6222 15.5353 -13.8051 -16.5385 15.4733 -13.7669 -16.4550 15.4113 -13.7287 -16.3716 15.3493 -13.6904 -16.2884 15.2873 -13.6521 -16.2053 15.2253 -13.6138 -16.1223 15.1634 -13.5755 -16.0395 15.1014 -13.5372 -15.9568 15.0395 -13.4988 -15.8742 14.9776 -13.4604 -15.7918 14.9157 -13.4220 -15.7095 14.8538 -13.3835 -15.6273 14.7919 -13.3451 -15.5453 14.7301 -13.3066 -15.4634 14.6682 -13.2681 -15.3816 14.6063 -13.2295
For definition of a proper rotation matrix R, use either the functions rotx etc or look up the formula at Wikipedia. %typically a point is a column vector. To match common definitions, transpose P P=P' %get center of rotation C=P(:,end) %translate P=bsxfun(#minus,P,C) %Rotate P=R*P %invert translation P=bsxfun(#plus,P,C)
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.')