MATLAB Answers

How to fix "Error using == Arrays have incompatible sizes for this operation." in this code?

1.503 views (last 30 days)
Hi, I am writing the following code:
for k = 1 : length(theFiles) % files are alreaady defined in original code
p=1;
t=1;
for q=1:43 % there are 43 inputs for arr
c=corr2(B0,mask);
arr(p)=abs(c);
if(arr(p)<1)
if(arr(p)>0.85)
cor(t)=arr(p);
t=t+1;
end
end
p=p+1;
end %end of q loop
mx=max(cor); %conditioned arr
ixa=find(arr==mx,1) %find the location for which mx matches arr value the first instance
But when run, the result shows following:
Error using ==
Arrays have incompatible sizes for this operation.
Error in Untitled12 (line 264)
ixa=find(arr==mx,1);
It is noteworthy that, the error shows only for certain image inputs. For other inputs, the code works fine.
How can I fix it?

Accepted Answer

KSSV
KSSV on 7 Jul 2021
Error is clear, you are trying to equate arr and mx. Check do they have same dimensions? They have different dimensions that's why error.
A = rand(2) ; B = rand(2) ;
A == B % no error as the dimensions are same
ans = 2×2 logical array
0 0 0 0
C = rand(3) ;
A == C % error as the dimensions are different
Arrays have incompatible sizes for this operation.
  2 Comments
Shreen El-Sapa
Shreen El-Sapa on 3 Aug 2021
i have the sameproblem. could u help me?
the program is
A=[ -0.00767
0.00696
-0.00031
0.00005
-0.00001
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000];
B=[ 0.12000
0.00209
-0.00019
0.00001
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
.00000E+00
.00000E+00
.00000E+00
.00000E+00
0.00000
0.00000
0.00000
0.00000
0.00000];
a = 1 ; %RADIUS
L=.4;
c =-a/L;
b =a/L;
m =a*200; % NUMBER OF INTERVALS
[x,y]=meshgrid((c:(b-c)/m:b),(c:(b-c)/m:b)');
[I J]=find(sqrt(x.^2+y.^2)<(a-.1));
if ~isempty(I)
x(I,J) = 0;
y(I,J) = 0;
end
r=sqrt(x.^2+y.^2);
t=atan2(y,x);
warning off
chi=1;alpha=1;ab1=1;
k=sqrt(chi.^2+alpha.^2); %xi=sqrt(t.^2+k.^2);
%for i=2:5
i=10;
h=@(t1)((t1-sqrt(t1.^2+k.^2)).^(-1).* (t1.*(exp(-sqrt(t1.^2+k.^2).*(r.*cos(t)+ab1))-exp(-t1.*(r.*cos(t)+ab1))).*(((-1).^(i-1).*t1.^(i-1).*exp(-ab1.*t1)./factorial( i ))+((-1).^(i).*sqrt(pi.*k./2/t1.^2).*exp(-ab1.*sqrt(t1.^2+k.^2)).*gegenbauerC(i,-1./2, sqrt(t1.^2+k.^2)./k))).*t1.*besselj(1,t1.*r.*sin(t))));
v=@(t1)((t1-sqrt(t1.^2+k.^2)).^(-1).* ((-t1.*exp(-sqrt(t1.^2+k.^2).*(r.*cos(t)+ab1))+sqrt(t1.^2+k.^2).*exp(-t1.*(r.*cos(t)+ab1))).*(((-1).^(i).*t1.^(i-1).*exp(-ab1.*t1)./factorial( i ))+((-1).^(i-1).*sqrt(pi.*k./2/(t1.^2+k.^2)).*exp(-ab1.*sqrt(t1.^2+k.^2)).*gegenbauerC(i,-1./2, sqrt(t.^2+k.^2)./k))).*t1.*besselj(1,t1.*r.*sin(t))));
h11=integral(h, 0, 10); %inf
h22=integral(v, 0, 10);%inf
Ai=A(i-1);Bi=B(i-1);
psi1=psi1+(Ai.*(r.^(-i+1)+h11)+(r.^(1./2).*besselk(i-1./2,r.*alpha)+h22).*Bi).*gegenbauerC(i,-1./2, cos(t));
%end
[DH1,hh2]=contour(x,y,psi,10,'-k');
%clabel(CH,h1,'FontSize',8);clabel(DH,h2,'FontSize',8)
hold on
m1=100;
r1=ones(1,m1+1)*a;
th=(0:2*pi/m1:2*pi);
set(polar(th,r1,'-k'),'LineWidth',1.1);
title('$\kappa=0$','Interpreter','latex','FontSize',10,'FontName','Times New Roman','FontWeight','Normal')
ylabel({'$\eta=1\quad$'},'Interpreter','latex','FontSize',10,'rot',360,'FontName','Times New Roman','FontWeight','Normal');
%title('Happel$^\prime$s model','Interpreter','latex','FontSize',10,'FontName','Times New Roman','FontWeight','Normal')
%axis square
axis off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
outcomes
Arrays have incompatible sizes for this operation.
Error in
test>@(t1)((t1-sqrt(t1.^2+k.^2)).^(-1).*(t1.*(exp(-sqrt(t1.^2+k.^2).*(r.*cos(t)+ab1))-exp(-t1.*(r.*cos(t)+ab1))).*(((-1).^(i-1).*t1.^(i-1).*exp(-ab1.*t1)./factorial(i))+((-1).^(i).*sqrt(pi.*k./2/t1.^2).*exp(-ab1.*sqrt(t1.^2+k.^2)).*gegenbauerC(i,-1./2,sqrt(t1.^2+k.^2)./k))).*t1.*besselj(1,t1.*r.*sin(t))))
(line 77)
h=@(t1)((t1-sqrt(t1.^2+k.^2)).^(-1).*
(t1.*(exp(-sqrt(t1.^2+k.^2).*(r.*cos(t)+ab1))-exp(-t1.*(r.*cos(t)+ab1))).*(((-1).^(i-1).*t1.^(i-1).*exp(-ab1.*t1)./factorial( i
))+((-1).^(i).*sqrt(pi.*k./2/t1.^2).*exp(-ab1.*sqrt(t1.^2+k.^2)).*gegenbauerC(i,-1./2,
sqrt(t1.^2+k.^2)./k))).*t1.*besselj(1,t1.*r.*sin(t))));
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
Error in test (line 80)
h11=integral(h, 0, 10); %inf
Related documentation
>>

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by