finding out Mahalanobis distance between two matrix
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have two matrix
G1 =
80.00
79.43
78.89
78.38
77.90
77.45
77.03
76.63
G2 = NaN NaN NaN
NaN NaN NaN
NaN 79.11 NaN
NaN 78.64 NaN
NaN 78.13 78.14
77.46 NaN 77.66
77.07 77.08 NaN
76.74 NaN NaN
I want to have result matrix which has a size of 8*1. Moreover, the G2 matrix elements should be compared with G1 and the nearest elements (Using only Mahalonobis distance) of G2 to G1 shoud be filled up in desired matrix. for example first one of G2 row has NaN, so it keep it NaN. 4th row of G2 has two values, this values should be compared with 4th element of G1 and nearest value shoud be filled up using Mahalanobis distance in the result matrix. When there is a single value than it shoud be remain like this only. When there are more than two values than the nearest value using mahalanobis distance shoud be filled up in the matrix.
Below is the desired output. How to do it more dynamically. i just did it by manually.
Result = NaN
NaN
79.11
78.64
78.14
77.46
77.07
76.744
i have already the solution for nearest neighbour way but i want it using Mahalanobis distance. When i tried using Mahal function than the error is that coloums should be same in both matrixs.
0 comentarios
Respuestas (1)
VM Sreeram
el 5 de Jul. de 2023
I am not sure why you got the error unless you share your implementation. You might have missed the transpose in line 9 of my implementaion.
G1 = [80.00; 79.43; 78.89; 78.38; 77.90; 77.45; 77.03; 76.63];
G2 = [NaN NaN NaN; NaN NaN NaN; NaN 79.11 NaN; NaN 78.64 NaN; NaN 78.13 78.14; 77.46 NaN 77.66; 77.07 77.08 NaN; 76.74 NaN NaN];
Result = nan(size(G1));
for i = 1:size(G2,1)
row = G2(i,:);
row = row(~isnan(row));
if ~isempty(row)
d = mahal(row', G1(i)); % row'
[~, idx] = min(d);
Result(i) = row(idx);
end
end
Result
0 comentarios
Ver también
Categorías
Más información sobre NaNs en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!