How to match unequal number of row elements, m-column numeric data

2 views (last 30 days)
Hi All,
I have A vector of nx1 length and a group of m-columns of unequal number of rows (<=n). I want to compare my A vector will all m- column elements and the output would be such that out of m-columns which column have closest values to my A vector will be shorted out (from high to low preference). Please give me some directions, how to match such numeric data.If anyone want more information, please let me know.
Very thanks in advance! Keshav Dev Singh UWO,IIT

Answers (1)

Sean de Wolski
Sean de Wolski on 18 Jul 2011
A = 1:5; %sample vec
B = magic(4); %sample matric
[C, mindex] = min(min(bsxfun(@(x,y)abs(x-y),reshape(A,[1 1 numel(A)]),B),[],1),[],3);
Something along these line. I can't give you complete code though since I'm not sure what you mean by shorting out highest to low. Can you give an example with data maybe for a 3x1 vector and 2x2 matrix?
The above works like this
  1. sample data
  2. minimum absolute difference of every value in vector to every value in column
  3. keep lowest value in column-wise throughout third dimension
  4. keep lowest value and its index page-wise to give you a row vector of data and indices corresponding to the smallest value.
Once again, an example would be clutch.
  2 Comments
Keshav Dev Singh
Keshav Dev Singh on 18 Jul 2011
Very Thanks Sean de!
Please find my A-vector and B-Unequal number of rows data columns. I want to match my A-vector values with 7 columns of B and then short each column of B from high to low preference (1 to 7 according to best match with A-vector)
Looking forward to here from you...
My DATA (left to right size(A)=15x1 and size(B)=15x7):
A and B-Unequal Row Matrix
7.406 8.669 9.175 8.757 8.443 8.880 8.655 8.471
8.513 10.047 9.809 9.175 8.655 9.583 9.063 8.910
8.728 10.134 10.286 9.567 9.192 10.797 9.460 10.825
8.817 11.030 11.495 10.066 9.460 11.809 12.644 11.261
9.241 11.422 12.000 10.891 9.856 12.706 13.026 12.492
9.856 13.434 13.899 12.227 12.000 13.361 13.899 12.769
11.469 NaN NaN 12.552 12.644 13.788 NaN NaN
12.492 NaN NaN 13.191 13.058 NaN NaN NaN
12.769 NaN NaN 13.465 13.824 NaN NaN NaN
13.293 NaN NaN 13.715 NaN NaN NaN NaN
13.824 NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN
Sean de Wolski
Sean de Wolski on 18 Jul 2011
So you want to sort (not short?) according to how well each vector is matched to A. How do you want to compare values? (minimum sum of absolute differences okay?) What about how to handle NaNs? Just discount them?
Please take the above data and show the expected result with operations characterized.

Sign in to comment.

Categories

Find more on Block and Blockset Authoring 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!