SVD plot

Description

Simple scripts that plots the outputs of SVD in a more readable format.

%% Description
% Plot the first n components of U and V
% Plot diag(S) normalized to first singular value
% x and y are axes that contain meaningful units, if unavailable use
% [r,c] = size(z); x = 1:c; y = 1:r;
function [U,S,V] = svdplots(x,y,z,n)
[U,S,V] = svd(z);
%% Normalized singular values
% s(1) is normalized to 100%
s = diag(S);
s = s./s(1).*100;
figure();
stem(s)
title('diag(S)');

ylabel('% of 1^{st} s.v.');
xlabel('singular value #');
xlim([1 n+10]);
ylim([0 s(2)*1.1]);
%% U matrix, row information
figure();
plot(y,U(:,1:n));
l = 1:n;
legend(num2str(l'));
xlabel('y units'); % Not general
title('U(:,1:n)');
%% V matrix, column information
figure();
plot(x,V(:,1:n));
l = 1:n;
legend(num2str(l'));
xlabel('x units'); % Not general
title('V(:,1:n)');
end

https://matlab1.com/shop/matlab-code/matlab-scripts-target-generation-calculation-integrals/
https://www.cs.cmu.edu/~tom/10701_sp11/slides/pca_wall.pdf

Reviews

There are no reviews yet.

Be the first to review “SVD plot”
Category: