passing image to function

10 views (last 30 days)
Lukas Goldschmied
Lukas Goldschmied on 1 Jun 2017
Commented: John D'Errico on 1 Jun 2017
When I pass an image to my function, I get the error: In an assignment A(:) = B, the number of elements in A and B must be the same. My code is:
function [F,C]=factorImage3a(d_pp)
%d_pp is the image
%name='/Users/Peter/archive/speichel.dcm';
%info=dicominfo(name);
matrix=128;
nf=2;
ni=100;
%d_pp=dicomread(h);
%--------------------------------------------------------------------------
is=matrix; % image size
np=is*is; % number of pixels
%--------------------------------------------------------------------------
% convert images to vectors
v=zeros(np,1);
d=zeros(np,ni);
for i=1:ni
v(:)=d_pp(:,:,:,i);
d(:,i)=v;
end
clear d_pp h
%--------------------------------------------------------------------------
% PRINCIPAL COMPONENT ANALYSIS - for variants and details cf Matlab help
%[coeff,score,latent]=pca(zscore(d));
%[coeff,score,latent]=pca(d);
%[coeff,score]=princomp(zscore(d));
[cf,P]=princomp(d); %(:,4:13));
%--------------------------------------------------------------------------
%[fc,~,~,~,F]=factoran(d,nf,'rotate','varimax','scores','wls','maxit',5000);
[fc,~,~,~,F]=factoran(d,nf,'rotate','varimax','scores','wls','maxit',7000);
% rotate - for details cf Matlab help
% none
% equamax
% orthomax
% parsimax
% pattern
% procrustes
% promax
% quartimax
% varimax
% scores - for details cf Matlab help
% wls or Bartlett
% regression or Thomson
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
% extraction of factor curves
m=max(F);
for i=1:nf
F(:,i)=F(:,i)/m(i);
end
%C=d(:,4:13)'*F/(F'*F);
C=d'*F/(F'*F);
%--------------------------------------------------------------------------
%figure % figure 3
a=zeros(is);
for i=1:nf
%a(:)=F(:,i);
end
for i=(nf+1):2*nf
%subplot(2,nf,i);
%plot(C(:,i-nf),'o-');
%grid on
%set(gca,'XLim',[0,11],'YLim',[0,35]);
%ts=['FACTOR CURVE ',int2str(i-2)];
%title(ts,'FontSize',12);
end
%--------------------------------------------------------------------------
end
end
How can I fix that?
  1 Comment
John D'Errico
John D'Errico on 1 Jun 2017
This is not a question of when you pass an image to the function. Just a bug in your code. And we cannot debug your code, because we can't run it. However, you can supply the ENTIRE text of the error message. Everything in red. That will tell someone what line the error was in. Then provide enough information, like what size is the array d_pp, as I am willing to guess that will probably be your problem.

Sign in to comment.

Answers (0)

Categories

Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!