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

カテゴリ

Help Center および File ExchangeDimensionality 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