Skip to content

Instantly share code, notes, and snippets.

@theptrk
Created April 20, 2020 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theptrk/01e7d0eecb438ce7df36e39c93398363 to your computer and use it in GitHub Desktop.
Save theptrk/01e7d0eecb438ce7df36e39c93398363 to your computer and use it in GitHub Desktop.
function Z = projectData(X, U, K)
% Initalize
Z = zeros(size(X, 1), K);
% index to create Ureduce
Ureduce = U(:, 1:K)
for i=1:size(Z,1)
% say X is all examples at dimension n (m, n)
% x is a single example (1, n)
x = X(i, :);
% we multiple the example by Ureduce to reduce dimensionality
% z is (1, n) * (n, K) = (1, K)
z = (X(i, :) * Ureduce)
% set z in the Z matrix
Z(i, :) = z;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment