Approximate match between two matrices
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Arif Hoq
il 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 Commenti
Voss
il 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)))
Più risposte (0)
Vedere anche
Categorie
Scopri di più su String Parsing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!