How to take 1 row on table 1 and compute it against every row of table 2 and do this for each row in table 1
Show older comments
Hello all, I have table 1 with 30 rows, and I have table 2 with 50 rows. Each table contains an X, Y, and Z coordinate point. I need to take each row individually of table 1 and find the absolute difference from every row of table 2 between the coordinates and have it return the smallest value for that specific row in table 1.
Ideally i would like the code to return the ID number of the smallest value that was found. I will attempt to explain mathmatically below what I need:
For the first row in table 1, called ID:1 values could be [ 100, 200, 300] and the table 2 has 4 rows as such: ID:1 [120, 235, 480], ID:2 [150, 207, 380], ID:3 [109, 210, 391], ID:4 [108, 216, 310].
absolute(100-120)+absolute(200-235)+absolute(300-480)= 235
absolute(100-150)+absolute(200-207)+absolute(300-380)= 137
absolute(100-109)+absolute(200-210)+absolute(300-391)= 110
absolute(100-108)+absolute(200-216)+absolute(300-310)= 34
So the code would recognize that 34 is the smallest value and corelate it to ID:4 on table 2 and would return the output to be ID:4
The above example is for only 1 row in table 1 imagine having to do it 30 times like the attached file has and having to do it 50 times for each of the 30 rows.
Attached is the excel file where I included random numbers for each table.
I am really hoping this makes sense and someone can help me. My experience is low and this is for a work project that I was thrown into. Please help. Thanks
Accepted Answer
More Answers (0)
Categories
Find more on NaNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!