passing image to function

조회 수: 2 (최근 30일)
Lukas Goldschmied
Lukas Goldschmied 2017년 6월 1일
댓글: John D'Errico 2017년 6월 1일
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
John D'Errico
John D'Errico 2017년 6월 1일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by