Adding Means to a matrix

I have 500*30 data matrix woith computed neans means 1*30 matrix . is there a way i can add all the column means in the latter to all the elements in the former. please help

回答(1 个)

Voss
Voss 2024-4-9
编辑:Voss 2024-4-9
Like this?
D = rand(500,30); % data
M = mean(D,1); % mean of each column of data
whos D M
Name Size Bytes Class Attributes D 500x30 120000 double M 1x30 240 double
% add each column to its mean:
result = D+M
result = 500x30
1.3120 0.9836 1.0394 0.7667 0.9814 0.8004 0.9753 0.6494 1.2657 0.5960 0.6222 1.4424 1.3174 1.1643 1.1265 0.7037 0.9213 0.9340 1.2963 1.0443 0.9834 0.5769 1.1242 0.5363 0.6212 0.8625 1.1283 1.1723 0.6862 0.6154 0.9852 0.5541 0.5909 1.3173 1.2458 1.0429 1.0127 0.8964 0.9000 0.9453 1.2488 0.8662 0.9984 0.8365 0.6174 0.9993 1.2898 0.9565 0.8885 0.5414 0.7077 0.8411 1.1811 0.6820 1.2467 0.7416 1.1344 1.1624 1.1259 1.3528 1.3350 0.8911 1.4933 0.9698 0.9478 0.6346 1.0940 0.5987 1.0179 1.0424 0.9792 1.3247 0.7250 1.4247 1.4086 1.1145 1.4746 0.6653 1.3605 0.6518 1.3063 1.4197 0.9216 1.1212 0.8123 0.9358 0.5731 0.8654 1.3047 0.8543 0.8401 1.2081 0.6872 0.5464 1.3056 1.3332 0.6344 1.0987 0.8508 0.8427 1.0010 1.3674 0.7532 0.8286 1.2486 0.7172 0.9975 0.8890 0.7491 0.7753 0.5483 0.7889 0.9812 0.7461 0.6505 0.7486 1.1513 0.9585 1.0650 0.8361 1.5055 1.4685 0.5741 1.0606 1.4039 0.7600 1.3011 1.3747 0.8826 1.4895 0.9448 0.7519 1.0620 1.0039 1.3561 0.7855 1.3943 0.6000 1.2513 0.6094 1.2646 1.0534 1.0667 1.3392 1.2012 0.7724 1.4248 1.4145 0.9847 0.5737 1.1253 0.6324 0.5180 1.3628 0.9043 1.4413 0.6683 1.1466 0.5966 1.1236 0.9366 1.1199 0.8404 0.5605 1.2325 0.9307 0.9865 1.1496 1.3045 0.8823 0.5675 0.5186 1.0427 1.1673 1.1042 1.4839 1.0412 1.3252 1.2867 0.9163 1.1311 0.8907 1.0784 1.3239 1.4506 1.4177 0.5801 0.8631 0.7527 0.8415 1.2373 1.0401 1.4399 0.8119 0.7225 0.6026 1.4024 0.6272 1.0162 0.5957 1.0932 1.1936 0.9376 1.1012 0.8544 1.1679 0.4956 0.7298 0.5985 1.3618 1.1360 0.9975 1.2324 1.2314 1.4730 1.1757 0.7307 1.4316 1.2189 0.5458 1.0379 0.5405 0.6956 0.5078 1.3944 0.6476 0.9721 1.3996 0.5584 1.1030 0.9968 0.8026 1.0379 1.1317 0.7286 0.9263 1.1791 1.2647 0.6494 1.3204 0.9394 0.5497 1.0721 1.2309 0.5532 1.1609 1.3285 0.7922 0.9332 0.8536 1.1920 1.2420 0.9282 0.9045 0.8093 1.3166 1.4909 0.9111 0.8105 0.7374 0.8272 0.7439 0.5558 1.3502 1.0819 1.4941 0.8443 0.5287 0.8577 0.7865 1.0862 0.8086 0.8009 0.9057 0.5128 1.1596 0.9445 0.5409 0.5257 1.0469 0.5941 1.2461 0.6806 1.3322 0.7766 1.4211 0.6462 1.3683 0.8177 0.5827 0.9178 1.1176 0.8053 1.3772 0.5721 1.2862 0.7199 0.5641 1.0340 0.9563
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Or like this?
% append means to the bottom of the matrix:
result = [D; M]
result = 501x30
0.8061 0.4732 0.5314 0.2704 0.4757 0.2781 0.4934 0.1498 0.7604 0.0999 0.1189 0.9217 0.8366 0.6618 0.6255 0.2076 0.4107 0.4513 0.7922 0.5535 0.4684 0.0929 0.6190 0.0367 0.1081 0.3574 0.6624 0.6813 0.1686 0.1142 0.4793 0.0438 0.0829 0.8211 0.7402 0.5206 0.5308 0.3967 0.3946 0.4492 0.7454 0.3455 0.5176 0.3340 0.1164 0.5031 0.7793 0.4738 0.3844 0.0506 0.1927 0.3571 0.6759 0.1824 0.7336 0.2365 0.6685 0.6714 0.6083 0.8517 0.8292 0.3808 0.9853 0.4735 0.4422 0.1123 0.6121 0.0990 0.5125 0.5463 0.4758 0.8040 0.2443 0.9222 0.9076 0.6184 0.9640 0.1826 0.8564 0.1611 0.7913 0.9357 0.4164 0.6216 0.2992 0.4307 0.1072 0.3743 0.7871 0.3531 0.3342 0.6978 0.1792 0.0502 0.8000 0.8108 0.1525 0.5991 0.3455 0.3466 0.4976 0.8467 0.2725 0.3261 0.7476 0.2210 0.4869 0.4063 0.2450 0.2846 0.0333 0.3049 0.4760 0.2465 0.1374 0.2435 0.6854 0.4674 0.5475 0.3349 0.9996 0.9581 0.0661 0.5644 0.8982 0.2377 0.8193 0.8750 0.3772 0.9934 0.4414 0.2312 0.5813 0.5014 0.8551 0.2894 0.8837 0.1173 0.7472 0.1187 0.7495 0.5695 0.5615 0.8396 0.6881 0.2673 0.9589 0.9234 0.4672 0.0725 0.6194 0.1220 0.0100 0.8665 0.3987 0.9190 0.1864 0.6470 0.0912 0.6274 0.4332 0.5992 0.3596 0.0580 0.7315 0.4345 0.4760 0.6669 0.8004 0.3916 0.0524 0.0346 0.5376 0.6677 0.5911 0.9788 0.5753 0.8342 0.7691 0.4151 0.6252 0.3803 0.5704 0.8277 0.9449 0.8954 0.0982 0.3635 0.2474 0.3454 0.7339 0.5194 0.9591 0.3094 0.2215 0.1065 0.8918 0.1445 0.5121 0.1049 0.5781 0.7096 0.4324 0.6016 0.3413 0.6628 0.0297 0.2387 0.0810 0.8606 0.6301 0.4871 0.7244 0.7351 0.9674 0.6534 0.2488 0.9320 0.7135 0.0497 0.5345 0.0198 0.2149 0.0053 0.8934 0.1514 0.4616 0.9169 0.0543 0.6123 0.4818 0.3187 0.5328 0.6321 0.2156 0.4212 0.7132 0.7736 0.1319 0.8192 0.4335 0.0393 0.5641 0.7347 0.0475 0.6386 0.8466 0.2925 0.4278 0.3575 0.6886 0.7213 0.4475 0.4020 0.3083 0.8204 0.9804 0.4284 0.3064 0.2466 0.3122 0.2599 0.0506 0.8506 0.5688 0.9890 0.3785 0.0377 0.3401 0.2853 0.5803 0.2983 0.2928 0.4094 0.0072 0.6372 0.4626 0.0412 0.0204 0.5508 0.0907 0.7254 0.1998 0.8297 0.2756 0.9250 0.1357 0.8855 0.3136 0.0920 0.4028 0.6336 0.3002 0.8776 0.0591 0.7811 0.2540 0.0730 0.5164 0.4551
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

提问:

2024-4-9

编辑:

2024-4-9

Community Treasure Hunt

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

Start Hunting!

Translated by