got error 'Attempt to execute SCRIPT pca as a function'
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
w = 1./var(jointdata);
[wcoeff,score,latent,tsquared] = pca(jointdata,...
'VariableWeights');
Attempt to execute SCRIPT pca as a function:
C:\Users\Adnan Gujjar\Desktop\MSProject\pca.m
i want to apply PCA in it why i got error can any one help me??
4 comentarios
MUHAMMAD ADNAN
el 18 de Mayo de 2015
Editada: Guillaume
el 18 de Mayo de 2015
Jan
el 18 de Mayo de 2015
@Muhammad: Please answer Stephens question: What do you get when to type this command in the command window:
which pca
Or even better:
which pca -all
Respuestas (2)
Walter Roberson
el 18 de Mayo de 2015
Your file C:\Users\Adnan Gujjar\Desktop\MSProject\pca.m does not have its first non-comment line starting with
function SOMETHING = pca(SOMETHING)
It needs to do so if you want to call upon it to return a calculated result.
7 comentarios
Walter Roberson
el 18 de Mayo de 2015
What filename are you using now? And exactly what error message are you getting now?
Hassan Macanga
el 28 de Abr. de 2020
Editada: Walter Roberson
el 29 de Abr. de 2020
clc
clear
input_dir = 'user/mac/desktop/python/eigenfacematlab/eigenface24/train';
testdir= 'user/mac/desktop/python/eigenfacematlab/eigenface24/test';
image_dims = [200, 180];
classes=[0;1;2;3;4;5;6;7;8;9];
num_images = 170;
images = [];
imageclasses=[];
disp(num_images);
counter = 1;
c = cell(170,1);
c{1}={''};
file=cell(170,1);
file(1)={''};
paths = fullfile(testdir,{'0','1','2','3','4','5','6','7','8','9'});
pathsA = fullfile(testdir,{'0','1','2','3','4','5','6','7','8','9'});
for i = classes(1):classes(10)
filenames = dir(fullfile(input_dir,int2str(i),'\*.jpg'));
num_images = size(filenames,1);
for n = 1:num_images
%filenames = dir(fullfile(input_dir, '*.jpg'));
%disp(filenames)
filename = fullfile(input_dir,int2str(i), filenames(n).name);
disp(filename)
ij=cellstr(filename);
k=cellstr(filenames(n).name);
file{counter}=(k);
disp(filename)
img = imread(filename);
img = rgb2gray(img);
img = im2double(img);
c{counter}=(1i);
images(:, counter) = img(:);
imagesclasses(:,counter)=i;
counter=counter+1;
end
end
num_images = 170;
counter = 170;
mean_face = mean(images, 2);
shifted_images = images - repmat(mean_face, 1, num_images);
[u, s, v] = pca(images');
num_eigenfaces = 20;
u = u(:, 1:num_eigenfaces);
features = u' * shifted_images;
testlabel=[];
cc=1;
testimages=[];
featuresvector=[];
predicition=[];
%testing
for i = classes(1):classes(10)
filenames1 = dir(fullfile(testdir,int2str(i),'\*.jpg'));
for n = 1:3
filename1 = fullfile(testdir,int2str(i),filenames1(n).name);
img = imread(filename1);
img = rgb2gray(img);
img = im2double(img);
figure(1)
imshow(img)
% if n == 1
% images = zeros(prod(image_dims), num_images);
% end
input_image(:, cc) = img(:);
testlabel(:,cc)=i;
feature_vec = u' * (img(:) - mean_face);
similarity = arrayfun(@(n) 1 / (1 + norm(features(:,n) - feature_vec)), 1:num_images);
% find the image with the highest similarity
[match, matchidx] = max(similarity);
A = reshape(images(:,matchidx), image_dims);
Predicition(:,cc)=imagesclasses(matchidx);
% display the result
%figure
%A=cell2struct(file,'name',1)
if 3%n=0
figure
imshow([img reshape(images(:,matchidx), image_dims)]);
title(sprintf('matches %f, score %0.2f', 1-match));
end
cc=cc+1;
end
end
confusionMatrix=confusionmat(testlabel,predicition);
%show mean face
a = reshape(mean_face, image_dims);
figure
imshow(a)
% display the eigenfaces
figure;
for n = 1:num_eigenvalues
subplot(2, ceil(num_eigenvalues/4), n);
ejector = reshape(u(:,n), image_dims);
images(ejector);
colormap(gray);
end
3 comentarios
Rik
el 28 de Abr. de 2020
Editada: Rik
el 29 de Abr. de 2020
This is not an answer, but a question. Please post it as your own question. Feel free to post a link to your question here.
For your reposted question, consider the following changes:
- either attach your m-file or use proper layout to make your question more readable
- post an exact description of what you are doing that produces this error (what is your current directory and how are you calling this script)
Walter Roberson
el 29 de Abr. de 2020
You have a script (not a function) named eigenfaces.m which you are attempting to invoke as if it were a function. However it is not clear to us where you are doing that, as you do not use eigenfaces in your code. Perhaps the file you posted is itself named eigenfaces.m and you are somehow invoking it as if it were a function.
Ver también
Categorías
Más información sobre Dimensionality Reduction and Feature Extraction en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!