Unable to get correct result using PCA (Principal component analysis) in MATLAB

1 次查看(过去 30 天)
Hi,
I have been using inbuilt function "pca" for my vertices data such as line, circle,ellipse and square. In case of a 45 degrees oriented square, the function does not work properly and is not oriented properly along x and y axis.
My code is as follows:
K = table2array(RawDataUnscaled);
scatter(K(:,1), K(:,2), 'r');
hold on;
EigenMatrix = pca(K);
FinalData = K*EigenMatrix;
scatter(FinalData(:,1), FinalData(:,2), 'b');
I would expect a graph (blue color plot),which has its orthogonal axis as X and Y axis, but instead I obtain the graph like the above attached one.
My data set is as follows:
-1924.5 709.824
-1924.5 715.528
-1924.5 721.231
-1924.5 726.935
-1924.5 732.638
-1924.5 738.341
-1895.98 766.859
-1867.46 795.376
-1793.32 846.707
-1747.69 875.224
-1724.88 892.334
-1679.25 932.258
-1656.43 955.072
-1610.81 1006.4
-1570.88 1052.03
-1536.66 1103.36
-1530.96 1120.47
-1508.15 1148.99
-1479.63 1188.91
-1462.52 1206.02
-1451.11 1217.43
-1428.3 1234.54
-1388.37 1257.35
-1331.34 1297.28
-1308.53 1314.39
-1280.01 1337.2
-1257.19 1354.31
-1200.16 1394.24
-1143.13 1439.86
-1103.2 1468.38
-1034.76 1514.01
-954.913 1559.63
-892.176 1605.26
-869.362 1622.37
-840.845 1639.48
-812.328 1662.3
-772.404 1696.52
-721.073 1736.44
-669.742 1770.66
-607.004 1816.29
-584.191 1827.7
-561.377 1844.81
-538.563 1850.51
-538.563 1856.21
-527.156 1861.92
-510.046 1867.62
-487.232 1873.32
-470.122 1884.73
-458.715 1890.43
-447.308 1901.84
-407.384 1918.95
-384.571 1936.06
-378.867 1924.65
-321.833 1890.43
-287.612 1867.62
-219.171 1821.99
-156.434 1787.77
-53.772 1753.55
8.96566 1719.33
71.7033 1690.81
168.662 1639.48
248.51 1605.26
345.468 1565.34
391.095 1548.23
459.536 1508.3
499.46 1485.49
539.384 1462.68
630.639 1428.46
687.673 1405.64
721.894 1382.83
761.818 1365.72
784.632 1348.61
824.555 1331.5
870.183 1308.68
927.217 1280.17
938.624 1268.76
961.438 1257.35
1029.88 1217.43
1075.51 1194.62
1132.54 1166.1
1161.06 1148.99
1200.98 1126.17
1229.5 1109.06
1246.61 1091.95
1309.35 1057.73
1320.75 1046.33
1360.68 1012.11
1394.9 994.996
1412.01 983.589
1429.12 966.479
1434.82 960.775
1446.23 949.368
1446.23 943.665
1451.93 920.851
1451.93 903.741
1457.64 886.631
1457.64 869.52
1457.64 852.41
1446.23 829.596
1423.42 801.079
1394.9 761.155
1360.68 715.528
1326.46 692.714
1280.83 647.087
1246.61 624.273
1195.28 567.239
1149.65 533.018
1104.02 498.798
1041.29 458.874
984.251 407.543
932.921 350.509
875.886 304.881
818.852 242.143
767.521 190.813
710.487 128.075
642.046 65.3373
596.418 25.4133
550.791 -14.5107
499.46 -54.4346
453.833 -88.6552
436.723 -105.765
391.095 -134.283
339.764 -174.207
316.951 -197.02
259.916 -236.944
225.696 -259.758
162.958 -305.385
128.738 -328.199
83.1102 -362.42
37.4828 -402.344
14.6691 -419.454
-36.6617 -453.674
-70.8823 -476.488
-99.3994 -499.302
-127.917 -522.116
-145.027 -533.522
-173.544 -550.633
-190.654 -567.743
-219.171 -584.853
-264.799 -601.963
-287.612 -613.37
-304.723 -619.074
-344.647 -624.777
-395.978 -624.777
-430.198 -624.777
-475.825 -624.777
-532.86 -624.777
-561.377 -619.074
-629.818 -613.37
-692.556 -601.963
-766.7 -590.557
-806.624 -584.853
-835.141 -579.15
-880.769 -562.039
-920.693 -544.929
-1006.24 -522.116
-1051.87 -499.302
-1126.02 -459.378
-1177.35 -436.564
-1228.68 -419.454
-1308.53 -385.233
-1376.97 -345.309
-1462.52 -311.089
-1508.15 -282.572
-1548.07 -254.055
-1616.51 -208.427
-1662.14 -185.613
-1747.69 -134.283
-1804.72 -100.062
-1850.35 -65.8415
-1884.57 -43.0278
-1947.31 -8.80724
-2044.27 36.8202
-2107.01 71.0407
-2164.04 105.261
-2186.85 122.372
-2226.78 150.889
-2278.11 173.702
-2306.63 202.22
-2335.14 225.033
-2357.96 242.143
-2369.36 270.661
-2380.77 287.771
-2392.18 304.881
-2392.18 321.991
-2397.88 339.102
-2397.88 356.212
-2397.88 361.915
-2397.88 379.026
-2397.88 384.729
-2380.77 396.136
-2346.55 413.246
-2329.44 424.653
-2300.92 436.06
-2266.7 458.874
-2221.07 481.687
-2209.67 493.094
-2192.56 504.501
-2169.74 527.315
-2152.63 544.425
-2124.12 567.239
-2101.3 578.646
-2089.89 590.052
-2078.49 595.756
-2067.08 601.459
-2061.38 612.866
-2044.27 624.273
-2038.56 624.273
-2032.86 635.68
-2021.45 641.383
-2015.75 647.087
-1992.94 664.197
-1970.12 681.307
-1941.61 709.824
-1930.2 715.528
-1913.09 732.638
-1901.68 744.045
-1890.27 755.452
-1878.87 766.859
-1873.16 766.859
  5 个评论
dpb
dpb 2018-10-29
Actually, it's a fignewton of a visual effect; if you compute
>> b=polyfit(M(:,1),M(:,2),1)
b =
0.0000 722.7947
>>
the slope is identically zero; it's just that the extreme points aren't quite symmetric that gives the visual appearance of a rotation.
You'd have to decide another measure of which it is that is the wanted measure of alignment. Perhaps that might be based on finding the locations of the min/max x-coordinates and fitting between those associated y-values altho that would be pretty noise-prone on single points.
You might try and see what happens if were to "flip" the lower half on top of the upper and then fit those; not sure if that mathematically washes out or not.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by