Why does the inner dimensions of the last line of my code not agree?

1 次查看(过去 30 天)
% subtract off the mean for each dimension
mn = mean(data,2);
mn2 = mean(data2,2);
data = double(data);
data2 = double(data2);
data = data - mn;
data2 = data2 - mn2;
% calculate the covariance matrix
covariance = cov(data,data2);
%covariance2 = (1 / (N-1)) * (data2'*data2);
% find the eigenvectors and eigenvalues
[PC, V] = eig(covariance);
% [PC2, V2] = eig(covariance2);
% extract diagonal of matrix as vector(so extracting the diagonal of
%the diagonal matrix)
%V = diag(V);
%V2 = diag(V2);
% sort the variances in decreasing order this will allow the PCs to be
% ordered the -1 makes it in descending, otherwise standard is ascending order
%[junk, rindices] = sort(-1*V);
%The value of rindices is the number of columns in V
%V = V(rindices);
%Making a PC matrix
%PC = PC(:,rindices);
% project the original data set
signals = PC * data;
I don't think anything is missing from my calculations and knowledge with PCA, but I get an error because the last line of my code does not allow me to get the signals once I project the zero meaned image on the image matrix that I want the signal of. Can someone explain me why? Cheers - Neo Cornel
  6 个评论
Neo
Neo 2016-1-11
编辑:Neo 2016-1-11
the data matrix is 262441x1 double PC is [1,0;0,1] V is [0,0;0,0]

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2016-1-11
You have:
signals = PC * data;
And PC is 2x2 and data is 262144x1. So you have a matrix multiplication of 2x2*262144x1. The inner dimensions are 2 and 262144 <== those are not the same numbers so you can't do that. Did you see my comment above about the d2 must be the same? Review your algorithm to make sure your equations are correct.
  2 个评论
Neo
Neo 2016-1-11
I mean I know that the error was the multiplication, I am asking where did the error occur in the code to make this happen?
Neo
Neo 2016-1-11
The equations are correct and I don't believe I am missing anything so can someone tell me what is it that gives me the error? I should have stated that before accepting the answer.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Earth, Ocean, and Atmospheric Sciences 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by