Approximate match between two matrices
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mohammed Rasul Iqbal
am 5 Feb. 2022
Kommentiert: Voss
am 5 Feb. 2022
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 Kommentare
Akzeptierte Antwort
Arif Hoq
am 5 Feb. 2022
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 Kommentare
Voss
am 5 Feb. 2022
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)))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu String Parsing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!