Principal component analysis pca

1 次查看(过去 30 天)
HI ALL, i need to help me when i run this code of pca i find this error please help me its urgent Thanks.
this is my error:
Undefined variable data.
Error in new_pca (line 35)
Training ( size ( Training ,1) +1 ,:)= data( counter ,:) ;
clc
clear all
% The total number of samples in each class is denoted by NSamples
NSamples =3;
% The number of classes
NClasses =30;
counter =1;
% Read the data
S=[];% S will store all the images
figure(1);
for i=1:NClasses
str = strcat('D:\eigenfaces\s\', int2str(i));
str = strcat(str, '.jpg');
eval('I=imread(str);');
I = rgb2gray(I);
I = imresize(I, [50,50]);
[m n]=size(I);
subplot(ceil(sqrt(NClasses)),ceil(sqrt(NClasses)),i)
%imshow(I)
if j==NSamples
title('TrainingDatasets','fontsize',18)
% Each image is represented by one column
data( counter ,:)=I (:) ;
% Y is the class label matrix
Y( counter ,1)=NClasses;
counter = counter +1;
end
drawnow;
end
NTrainingSamples =2;
counter =1;
Training =[]; Testing =[]; TrLabels =[]; TestLabels =[];
for i=1: NClasses
for j=1: NTrainingSamples
Training ( size ( Training ,1) +1 ,:)= data( counter ,:) ;
TrLabels ( size ( TrLabels ,1) +1 ,1)= Y( counter ,1) ;
counter = counter +1;
end
for j= NTrainingSamples +1: NSamples
Testing ( size ( Testing ,1) +1 ,:)= data( counter ,:);
TestLabels ( size ( TestLabels ,1) +1 ,:)= Y( counter ,1);
counter = counter +1;
end
end
clear data Y I;
tic

采纳的回答

sarine_nassima
sarine_nassima 2019-10-17
i have error in tow lines if any one correcte me probleme please .thank you
% Each image is represented by one column
data( counter ,:)=I (:) ;
% Y is the class label matrix
Y( counter ,1)=NClasses;

更多回答(1 个)

Walter Roberson
Walter Roberson 2019-10-22
编辑:Walter Roberson 2019-10-22
if j==NSamples
You did not assign to j by that point in the code, so it has its default value of sqrt(-1) which does not equal NSamples, so you never assign to data

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

标签

产品


版本

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by