Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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