How to match unequal number of row elements, m-column numeric data
2 ビュー (過去 30 日間)
古いコメントを表示
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
1 件のコメント
回答 (1 件)
Sean de Wolski
2011 年 7 月 18 日
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
- sample data
- minimum absolute difference of every value in vector to every value in column
- keep lowest value in column-wise throughout third dimension
- 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 件のコメント
Sean de Wolski
2011 年 7 月 18 日
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.
参考
カテゴリ
Help Center および File Exchange で Block and Blockset Authoring についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!