what kind of plot is useful for comparing two matrices?
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have two 5*5 matrices. I want to use a plot to show that they are close element-wise.
What plot is suitable?
I think the plot should be transparent.
It is of course doable if we reshape the matrices into vectors, and use a 2d plot. But that is not intuitive.
0 Commenti
Risposta accettata
Star Strider
il 9 Giu 2024
I am not certain that there is any built-in functtion for this sort of problem.
One approach —
M1 = randn(5)
M2 = M1 + randn(5)/10
Mcomp = sqrt((M1-M2).^2/numel(M1));
ms = fitdist(Mcomp(:),'lognormal')
lognparms = @(mu,sigma) [exp(mu + sigma^2/2); exp(2*mu + sigma^2) * (exp(sigma^2)-1); sqrt(exp(2*mu + sigma^2) * (exp(sigma^2)-1))]; % [mean; var; std]
lnparms = lognparms(ms.mu, ms.sigma);
fprintf(1,'\nMean = %.6f\nVar = %.6f\nStDv = %.6f\n',lnparms)
[X,Y] = meshgrid(1:5);
figure
stem3(Mcomp)
hold on
scatter3(X(:), Y(:), Mcomp(:), 50, Mcomp(:), 'filled')
patch([xlim flip(xlim)], [1 1 5 5], ones(1,4)*lnparms(1), 'k', 'FaceAlpha',0.25, 'EdgeColor','none')
hold off
colormap(turbo)
colorbar
axis('padded')
zlabel(["‘Mcomp’ Values For Each" "Comparison Matrix Element"])
The comparison value ‘Mcomp’ is a ‘sort of’ root-mean-square value. (It can be anything, providing it returns a matrix equal to the original matrices.) Since the ‘Mcomp’ calculation I chose can never be negative (and would likely be strictly positive, so non-zero as well), I chose the lognormal distribution to calculate its parameters. If you choose a different calculation, choose an appropriate distribution if you want to calculate its parameters. The gray patch is the mean of the ‘Mcomp’ values, as calculated from the lognormal distribution parameters.
.
5 Commenti
Più risposte (1)
Image Analyst
il 9 Giu 2024
Modificato: Image Analyst
il 10 Giu 2024
Why a plot and not a 2-D image showing differences? What would your x axis represent?
If you treat your matrix as an image there are lots of ways to compare images. For example imabsdiff, immse, psnr, etc. For example you could use imabsdiff and color code the magnitude of the differences in an image, or you could count the number of matches and mismatches. You could also make a histogram of the differences - that's a plot.
immse and psnr give single numbers gauging how close the matrices are to each other.
Here's some code
% Create two matrices
m1 = uint8(randi(255, 5, 5))
m2 = uint8(randi(255, 5, 5))
% Compute difference.
diffMatrix = imabsdiff(m1, m2)
% Display m1
subplot(2, 2, 1);
imshow(m1)
title('m1');
% Display m2
subplot(2, 2, 2);
imshow(m2)
title('m2');
% Display diffMatrix
p3 = subplot(2, 2, 3);
imshow(diffMatrix)
title('diffMatrix');
colorbar(p3)
colormap(p3, 'turbo')
0 Commenti
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots 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!