how to compare column values of a matrix with a column vector of different size?
Show older comments
Hello everyone, how can I compare a 10x5 matrix with a row vector, let me explain it better.
I have the vector
detected = [56
40
33
31
28
13
10
1]
and the matrix
M_transmision = 1 40 -84 -638 644
2 1 138 -276 308
3 31 -74 -157 173
4 28 -274 -511 580
5 13 53 -35 64
6 13 124 -367 388
7 56 30 -290 292
8 33 20 -263 263
9 28 -504 103 515
10 10 -118 -226 255
I need to compare the unique values of the detected vector with column 2 of the M_transmission matrix, and extract column 5 of the matrix from each unique value found.
for example the result would be the following.
result = [56 292
40 644
33 263
31 173
28 515
13 64
10 255
1 308]
note: If the numbers are repeated, as shown in this example, the number 13 and 28 are repeated, you have to extract the smallest number from column 5 of the matrix.
for instance
number 13 has:
13 64
13,388
and the number 28 has:
28,580
28,515
has to extract the smallest value, that is:
13 64 and 28 515
any help i will appreciate it
I was trying to do it like this, but I can't
detected(:,end+1:5)=missing;
detected = array2table(detected);
M_transmision = array2table(M_transmision);
result2 =innerjoin(M_transmision,detected,'LeftKeys',["M_transmision2"],'RightKeys',["detected1"]);
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!