new to PH and MATLAB, please help - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

new to PH and MATLAB, please help

blink1nceblink1nce Posts: 1Member
Hello all!
I am Brian, an electrical engineering student at Vanderbilt University. I am doing some research involving a PCA (Principal Component Analysis) in a spectroscopy project. Most of this code is taken from a tutorial, and I am trying to make it work for my project, where I have only one measurement per time sample instead of several. So, I have a (MxN) (1x2000) matrix, where the 2000 is the number of samples taken sequentially. I am getting an error on line 8. Please tell me why!
Any other comments or suggestions about this code are welcome.

function [signals,PC,V] = PCA_analysis_fromTutorial(data)
% PCA1: Perform PCA using covariance.
% data - MxN matrix of input data
% (M dimensions, N trials)
% signals - MxN matrix of projected data
% PC - each column is a PC
% V - Mx1 matrix of variances
MATRIX = importdata('C:UsersBrian NeavesDesktopPETN data for PCA analysis');
N = size(MATRIX);

% subtract off the mean for each dimension
mn = mean(data,2);
data = data - repmat(mn,1,N);
% calculate the covariance matrix
covariance = 1 / (N-1) * data * data;
% find the eigenvectors and eigenvalues
[PC, V] = eig(covariance);
% extract diagonal of matrix as vector
V = diag(V);
% sort the variances in decreasing order
[~, rindices] = sort(-1*V);
V = V(rindices);
PC = PC(:,rindices);
% project the original data set
signals = PC * data;
Sign In or Register to comment.