Approximate match between two matrices
13 次查看(过去 30 天)
显示 更早的评论
i have two vectors C1 is calculated using code and A1 is input vector. C1(1x4) = [0.4311 0.123 0.011 0.441] , A1(5x4)=
X A B C
0.11 0.13 13.46 0.87
0.01 0.10 10.47 0.90
0.44 0.12 12.19 0.88
0.43 0.09 9.24 0.91
0.06 0.07 7.15 0.93
Need to find approximate match between individual C1 value with A1(:,1) and should give the coresponding output of A(:,2),A(:,3) & A(:,4).
0 个评论
采纳的回答
Arif Hoq
2022-2-5
if there is no approximate value then it will return the minimum value of that column.
C1= [0.4311 0.123 0.011 0.441];
A1=[0.11,0.13,13.46,0.87;0.01,0.10,10.47,0.90;0.44,0.12,12.19,0.88;...
0.43,0.09,9.24,0.91;0.06,0.07,7.15,0.93 ];
A2=A1(:,1);
A3=A1(:,2);
A4=A1(:,3);
A5=A1(:,4);
[minValue1,nearestIndex] = min(abs(A2-C1(1,1)));
C1_first = A2(nearestIndex) % for the value C1=0.4311
[minValue2,nearestIndex] = min(abs(A3-C1(1,2)));
C1_second = A3(nearestIndex) % for the value C1=0.123
[minValue3,nearestIndex] = min(abs(A4-C1(1,3)));
C1_third = A4(nearestIndex) % for the value C1=0.011
[minValue4,nearestIndex] = min(abs(A5-C1(1,4)));
C1_fourth = A5(nearestIndex) % for the value C1=0.441
3 个评论
Voss
2022-2-5
As an alternative to the first method:
C1 = [0.4311 0.123 0.011 0.441];
A1 = [0.11,0.13,13.46,0.87; ...
0.01,0.10,10.47,0.90; ...
0.44,0.12,12.19,0.88;...
0.43,0.09,9.24,0.91; ...
0.06,0.07,7.15,0.93];
[min_diff,idx] = min(abs(A1-C1),[],1)
nearest_A1 = A1(sub2ind(size(A1),idx,1:size(A1,2)))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!