How to compare 2 columns line by line between two matrix of different size?
7 次查看(过去 30 天)
显示 更早的评论
Hello everyone, I am trying to collect data between 2 matrix, let me explain.
I have my first matrix1 of 128x26 --> in the future it will increase rows but not columns.
I have my second matrix2= 17x5 --> in the future it will increase rows but not columns.
I need to compare the first 2 columns of my matrix2 with the first 2 columns of my matrix1, if they match, store them in a new matrix and also add the value of row 1 column 5 of matrix2 to matrix1, it would now have 27 columns. for example.
matrix2 matrix1
looking at the figures of matrix1 and matrix2, the two values of column 1 and 2 of the first row of matrix2 are equal to the values of column 1 and 2 of the first row of matrix1?
If the answer is yes, as we see in the figures the condition is met, we must extract all that row from matrix1, also extracting the value of the first row of column 5 from matrix2 and store it in another matrix.
now next row the two values of column 1 and 2 of the second row of matrix2 are equal to the values of column 1 and 2 of the second row of matrix1?
As we see in this opportunity the condition is not met, then it would go to the next row of the matrix1.
we ask again the two values of column 1 and 2 of the second row of matrix2 are equal to the values of column 1 and 2 of the third row of matrix1?
we can see that this time the condition is not met either.
then he continues to go row by row through matrix1.
until it reaches row 13 of matrix where if the condition is met, the two values of column 1 and 2 of the second row of matrix2 are equal to the values of column 1 and 2 of the thirteenth row of matrix1?
s,i then extracts the entire row of matrix1, also extracting the value of the first column 5 row of matrix2 and storing it in another matrix. which would now be an array of ? x27.
any help will be of great help.
attached files datasetPDP.csv / M_reception.csv
matrix1 = readtable('datasetPDP.csv');
matrix2= readtable('M_reception.csv');
matrix1=table2array(matrix1);
matrix2=table2array(matrix2);
result = zeros(128,27); %create empty array to store
for ii = 1:numel(result)
if
% result(ii) = matrix1(1,2)== matrix2(:,2);
end
end
3 个评论
采纳的回答
Peter Perkins
2022-6-14
ismember will work, but ithis is a join operation. It's a one-liner:
>> matrix1 = readtable('datasetPDP.csv');
>> matrix2 = readtable('M_reception.csv');
>> outerjoin(matrix1,matrix2,"Type","left","LeftKeys",["Rodada" "Preamble"],"RightKeys",["Var1" "Var2"],"RightVariables","Var5")
ans =
128×27 table
Rodada Preamble Signal matrixpdp4 matrixpdp5 matrixpdp6 matrixpdp7 matrixpdp8 matrixpdp9 matrixpdp10 matrixpdp11 matrixpdp12 matrixpdp13 matrixpdp14 matrixpdp15 matrixpdp16 matrixpdp17 matrixpdp18 matrixpdp19 matrixpdp20 matrixpdp21 matrixpdp22 matrixpdp23 matrixpdp24 matrixpdp25 matrixpdp26 Var5
______ ________ __________ __________ __________ __________ __________ __________ __________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ____
1 0 0.0010973 0.0014955 0.0021707 0.003359 0.00055829 0.0010751 0.00090908 0.0014945 0.00019773 0.00078146 0.0012317 0.0030336 0.0017859 0.0018387 0.0012646 0.0018806 0.00027404 0.0021579 0.0033589 0.0012098 0.00072156 0.0036446 0.0026105 0.00024817 1
1 1 0.0010774 0.0017781 0.0018294 0.00091074 0.0045575 0.0067504 0.00080268 0.0022846 0.0036092 0.0013504 0.00053713 0.0041816 0.0024775 0.00058104 0.0037931 0.0029195 0.000371 0.00095127 0.0006796 0.00056264 0.0025798 0.0010398 0.001775 0.00075008 NaN
1 2 0.0020478 0.00085579 0.0040942 0.0025075 0.0044309 0.0011097 0.0011937 0.00041591 0.00056487 0.00038507 0.0019512 0.00017701 0.00045695 0.00044913 0.00039 0.0010628 0.0036834 0.0035462 0.0028797 0.0035931 0.0023936 0.002308 0.0023255 0.00096789 NaN
1 3 0.0010441 0.00049841 0.0008076 0.00097527 0.00010521 0.0011686 0.0027039 0.0021738 0.0015503 0.0023266 0.0027327 0.00097983 0.00054617 0.0032336 0.0041698 0.0038683 0.0014237 0.0013809 0.00052897 0.0038032 0.0061047 0.00046472 0.00044809 0.0022013 NaN
1 4 0.0012156 0.00068193 0.0018693 0.0026049 0.002205 0.0034968 0.0035514 0.0031294 0.0024362 0.0017798 0.0010075 0.0014272 0.0015431 0.000693 0.00079977 0.00090793 0.000403 0.0010627 0.00071093 0.0012673 0.0020034 0.0017955 0.0012529 0.00011641 NaN
1 5 0.0017177 0.00069686 0.00053142 0.0010268 0.003255 0.0025269 0.0011327 0.001645 0.0018237 0.0022081 0.0063273 0.009835 0.0041595 0.0015196 0.0020088 0.00066475 0.00032383 0.0018303 0.0032275 0.00099837 0.0022101 0.0016684 0.0012008 0.0018507 NaN
1 6 0.0012676 0.00045186 0.0013013 0.00030612 0.00047142 0.0019475 0.0021581 0.00079162 0.00064098 0.0016653 0.0013672 0.0011073 0.00077234 0.00094002 0.0060251 0.0041629 0.00034144 0.00046791 0.0010455 0.00051369 0.0031551 0.0032793 0.0012046 0.0021144 NaN
1 7 0.0015077 0.0032757 0.0033144 0.00085496 0.00051226 0.0014641 0.0017391 0.0017929 0.0061214 0.0029792 0.002147 0.0017308 0.0025274 0.0036399 0.005072 0.0035843 0.0001834 0.0029567 0.0029361 0.0016222 0.0012737 0.0021096 0.0036728 0.0040209 NaN
1 8 0.00095541 0.0005468 0.0011631 0.0018271 0.0021716 0.00021437 0.0023052 0.00082586 0.0027262 0.0021262 0.0075821 0.0043669 0.0031274 0.0030417 0.0019816 0.0027805 0.00012739 0.0029001 0.0024738 0.0034005 0.0042034 0.0014699 0.0049535 0.0012263 NaN
1 9 0.00084515 0.0013416 0.003956 0.0035951 0.00065921 0.0035955 0.00579 0.00033185 0.0022705 0.0012696 0.0022217 0.033807 0.064108 0.016413 0.0029541 0.0065956 0.0021655 0.0015788 0.001384 0.0013451 0.0021701 0.00085581 0.0012541 0.00082248 NaN
1 10 0.0042198 0.0019744 0.0012101 0.00080912 0.0007666 0.0018416 0.0027759 0.0027681 0.0070458 0.010774 0.0047063 0.0003923 0.0031841 0.0025231 0.0018007 0.00034417 0.0015265 0.002909 0.0021168 0.0020538 0.0012833 0.0012541 0.00065291 0.00052467 NaN
1 11 0.0012448 0.0031821 0.0010628 0.0034886 0.0018811 0.0057215 0.00010455 0.003405 0.0060808 0.0098973 0.066043 0.39196 0.22502 0.00022782 0.044542 0.0031209 0.0094781 0.0021576 0.0039872 0.00046216 0.0019244 0.0014773 0.00066253 0.0028552 NaN
1 12 0.0051382 0.0056502 0.0027458 0.0014817 0.00070129 0.0022945 0.0017992 0.0042692 0.0019376 0.011582 0.013746 0.16584 0.14764 0.0093603 0.0078227 0.0031041 0.0078368 0.00040088 0.0035873 0.0050905 0.0052621 0.0031892 0.00084777 0.001533 1
1 13 0.0024913 0.003497 0.0042391 0.0016327 0.00061685 0.00463 0.0019077 0.0014411 0.005991 0.005015 0.00051202 0.001849 0.0010992 0.0028671 0.0014481 0.001406 0.00089814 0.00062381 0.0008219 0.0041691 0.0016705 0.00017857 0.00071384 0.0027307 NaN
1 14 0.0028523 0.004434 0.0025021 0.00056743 0.0012753 0.0012606 0.00055734 0.0077045 0.0083289 0.0028868 0.0010419 0.088706 0.17242 0.037488 0.0035278 0.0061256 0.0012858 0.00064601 0.0022378 0.00049119 0.0004179 0.0031359 0.00066957 0.0031972 NaN
1 15 0.0040321 0.0012932 0.0023014 0.0025301 0.00046779 0.0016559 0.0028288 0.0024749 0.0015211 0.0020137 0.00044966 0.0031585 0.0066212 0.004233 0.0023557 0.00084482 0.0015047 0.00089751 0.0019532 0.0031834 0.0020053 0.0021094 0.0010083 0.00072187 NaN
1 16 0.004941 0.0026842 0.0005658 0.002517 0.0003222 0.00079508 0.00079265 0.0026782 0.00067126 0.00088311 0.00090814 0.0019914 0.0018319 0.0016373 0.0012236 0.00049719 0.0012321 0.0012921 0.00098165 0.00056793 0.001041 0.0007905 0.00097527 0.00080592 0
1 17 0.0022534 0.0030143 0.0055441 0.0044463 0.0025262 0.017061 0.0088768 0.0027206 0.0032895 0.010912 0.0055377 0.12246 0.12625 0.0092601 0.0047975 0.00032622 0.0043357 0.0020372 0.0015425 0.0015002 0.0011104 0.00091825 0.0007817 0.0029933 1
1 18 0.001874 0.0012292 0.00064677 0.0038169 0.0035081 0.00074153 0.00060098 0.0015003 0.0034444 0.0017952 0.0018087 0.0014346 0.0011685 0.0018915 0.001687 0.0012081 0.00014338 0.0017354 0.0016956 0.0013922 0.0016273 0.0021601 0.00095762 0.0013722 NaN
1 19 0.0004795 0.0017168 0.0010648 0.0020244 0.0010584 0.00119 0.0024165 0.0021458 0.00099231 0.0010357 0.0010782 0.0044558 0.0043473 0.0043934 0.004216 0.0013792 0.00073113 0.00049909 0.001429 0.0010402 0.00027421 0.0015057 0.0020146 0.0019079 NaN
: : : : : : : : : : : : : : : : : : : : : : : : : : :
2 44 0.0018129 0.00089776 0.0023699 0.0010181 0.0017192 0.00076182 0.0012447 0.0010925 0.001366 0.0012242 0.00033044 0.0010379 0.0010969 0.0015877 0.0044794 0.001343 0.0010353 0.0015873 0.0014389 0.0018233 0.00049561 0.00327 0.0055067 0.0047465 1
2 45 0.0035632 0.0063304 0.0052247 0.0020673 0.0017972 0.0036182 0.002434 0.00034105 0.00085688 0.0022339 0.0026449 0.0014151 0.00054098 0.00064258 0.0026553 0.001397 0.00096313 0.00030289 0.00020618 0.00053574 0.0022085 0.0016364 0.0027255 0.00090731 NaN
2 46 0.0007001 0.001716 0.00077849 0.0006116 0.0012149 0.00038342 0.0007744 0.00044005 0.0054269 0.0053465 0.00063063 0.0040887 0.0013102 0.00027688 0.0015623 0.003641 0.0032719 0.0011169 0.00090554 0.0022397 0.0017888 0.0011034 0.00090255 0.00092326 NaN
2 47 0.0022405 0.0013799 0.0012279 0.0012122 0.0022226 0.00021536 0.0021071 0.00073198 0.0011624 0.0036028 0.0034959 0.0015374 0.00055692 0.0039569 0.0064082 0.0010124 0.0031754 0.0024986 0.00079648 0.00020623 0.00042075 0.001327 0.00081575 0.0010912 NaN
2 48 0.00024619 0.0012901 0.0017184 0.0023425 0.0033145 0.00044313 0.00018129 0.001065 0.0015592 0.002021 0.0041724 0.0043461 0.0033273 0.0018234 0.0040704 0.0043786 0.0031738 0.0058246 0.0036726 0.0033272 0.0023244 0.001504 0.00082242 0.0013057 NaN
2 49 0.00077536 0.0010171 0.0018011 0.001866 0.0020243 0.0010971 0.00038052 0.00099761 0.00075259 0.00091204 0.00099607 0.0014106 0.0010843 0.003391 0.0018399 0.0013811 0.0021575 0.0055965 0.0046285 0.0013592 0.0017625 0.0036897 0.0027101 0.00057446 NaN
2 50 0.0014045 0.0012965 0.0012251 0.0013734 0.002685 0.00075175 0.0023342 0.0018544 0.0056375 0.0037256 0.0051981 0.00086322 0.00086701 0.0013212 0.00090445 0.00065787 0.00059062 0.0038797 0.0021087 0.0019733 0.0017831 0.00080594 0.001747 0.0015876 NaN
2 51 0.0035614 0.0013334 0.00067066 0.0012252 0.0012402 0.0013522 0.0010245 0.0028272 0.0055757 0.0017266 0.00040195 0.00057075 0.0011545 0.0017927 0.0031428 0.0039066 0.007246 0.10684 0.27881 0.12934 0.0055709 0.010839 0.0015755 0.0028047 1
2 52 0.0005097 0.0012164 0.0013328 0.00078055 0.002145 0.0023428 0.0011545 0.00064442 0.0011088 0.0017516 0.0032288 0.0054092 0.0029596 0.00080221 0.0024652 0.00086444 0.0019534 0.0028125 0.002938 0.0014227 0.00068893 0.003827 0.0015591 0.0028916 NaN
2 53 0.002149 0.00037247 0.0019154 0.0019518 0.0032624 0.003956 0.0032743 0.0019048 0.00038879 0.00058397 0.00045235 0.0016106 0.00043441 0.0011746 0.0016053 0.00083189 0.0023806 0.0037916 0.0045566 0.0010793 0.0025769 0.0027969 0.0009914 0.00018068 NaN
2 54 0.0017755 0.0029364 0.0010729 0.0027167 0.0044297 0.0015856 0.0015175 0.0015852 0.00074844 0.0024197 0.0024942 0.0019054 0.0020422 0.0010931 0.00091567 0.00069952 0.00025896 0.00091218 0.00097232 0.0012196 0.00060903 0.00089067 0.00067336 0.00092845 NaN
2 55 0.0030385 0.0019786 0.00043091 0.0019478 0.001599 0.00067014 0.0022767 0.0014854 0.00088575 0.0024318 0.0024133 0.0011435 0.0012668 0.00095854 0.0020945 0.0053136 0.0034482 0.00044109 0.0034679 0.0010682 0.0018075 0.00057173 0.0013796 0.0016545 NaN
2 56 0.0075449 0.0052677 0.00081658 0.0012355 0.00069084 0.0016768 0.00015458 0.00073926 0.00032303 0.00046185 0.0012235 0.00030528 0.00068002 0.0013886 0.0017564 0.0011536 0.0013455 0.00035626 0.0015029 0.0021757 0.0010432 0.00037814 0.0010076 0.0013477 1
2 57 0.0047445 0.0023403 0.0066734 0.0034636 0.0030496 0.001132 0.0045062 0.0018714 0.005971 0.0053931 0.0012656 0.0014415 0.0012442 0.0027818 0.0018774 0.0013538 0.0021553 0.0017431 0.00042992 0.0040285 0.0032781 0.0006399 0.0012157 0.0043137 NaN
2 58 0.0025177 0.0039624 0.0013396 0.0012327 0.0016084 0.00077188 0.00027701 0.00078746 0.00066841 0.00067663 0.00018197 0.0060773 0.005797 0.00016341 0.001688 0.004599 0.0017107 0.002735 0.00044471 0.024889 0.041071 0.0040108 0.0034443 0.0018994 NaN
2 59 8.1339e-05 0.00069285 0.0016601 0.00075471 0.0011265 0.0034647 0.00092708 0.0026734 0.0067707 0.0052703 0.00052984 0.0020042 0.0045039 0.0032346 0.004779 0.0035327 0.0025712 0.0053006 0.0089947 0.03699 0.014163 0.00074291 0.0014575 0.00083619 NaN
2 60 0.011836 0.0010351 0.0064164 0.0034499 0.0081156 0.0031529 0.0024829 0.00022536 0.00047512 0.0012795 0.0010406 0.0019063 0.0026321 0.0032091 0.0034932 0.0032668 0.0020201 0.00099025 0.0016848 0.0051396 0.0025274 0.00067372 0.00033823 0.00029294 NaN
2 61 0.0008977 0.00097358 8.4165e-05 0.0026509 0.0026732 0.0010886 0.0005029 0.00079601 0.0024851 0.0007122 0.0017964 0.0023497 0.00063573 0.003965 0.0007579 0.0056555 0.00085557 0.0028269 0.0033492 0.0092183 0.025056 0.20152 0.15012 0.0040343 NaN
2 62 0.0034501 0.0015632 0.0042426 0.002751 0.00080137 0.00039144 0.0018245 0.002492 0.00066393 0.0016724 0.00079415 0.0018821 0.0014331 0.0011794 0.00071549 0.0016982 0.0014695 0.0020075 0.0026873 0.0048475 0.00077319 0.00090235 0.00068204 0.0002192 NaN
2 63 0.0028523 0.0020075 0.00062044 0.00067918 0.0016999 0.004335 0.0015263 0.001882 0.0018724 0.00077001 0.001575 0.0033639 0.0018316 0.00081367 0.00025862 0.00032023 0.00045461 0.00069571 0.0016788 0.00096171 0.0015312 0.0009506 0.00042282 0.0027451 NaN
Display all 128 rows.
Probably the Type parameter is unnecessary, but it makes clear what you are doing.
3 个评论
Peter Perkins
2022-6-14
Giancarlo, look at the doc for innerjoin and outerjoin. It sounds like you want inner.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!