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

2 Ansichten (letzte 30 Tage)
% 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 Kommentare
Neo
Neo am 11 Jan. 2016
It's a bit big, let me know if you can see it now.
Neo
Neo am 11 Jan. 2016
Bearbeitet: Neo am 11 Jan. 2016
the data matrix is 262441x1 double PC is [1,0;0,1] V is [0,0;0,0]

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 11 Jan. 2016
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 Kommentare
Neo
Neo am 11 Jan. 2016
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 am 11 Jan. 2016
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by