Principal component analysis pca

조회 수: 1 (최근 30일)
sarine_nassima
sarine_nassima 2019년 10월 16일
편집: Walter Roberson 2019년 10월 22일
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

태그

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by