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

430 ビュー (過去 30 日間)
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?
  1 件のコメント
kanika bhalla
kanika bhalla 2021 年 7 月 7 日
@Tawsif Mostafiz Can you add those images on which your code gives error so that we can try and check what is a problem?

サインインしてコメントする。

採用された回答

KSSV
KSSV 2021 年 7 月 7 日
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.
  6 件のコメント
Walter Roberson
Walter Roberson 2023 年 2 月 9 日
If you change the calls to
h11=integral(h, 0, 10, 'arrayvalued', true); %inf
h22=integral(v, 0, 10, 'arrayvalued', true);%inf
then the integrals can proceed -- but they take a long time. Long enough that I do not know yet whether the steps after that would be compatible with the values returned by those statements.
Walter Roberson
Walter Roberson 2023 年 2 月 9 日
psi1=psi1+(Ai.*(r.^(-i+1)+h11)+(r.^(1./2).*besselk(i-1./2,r.*alpha)+h22).*Bi).*gegenbauerC(i,-1./2, cos(t));
Variable psi1 is not defined at that point in the code. For debugging purposes we can initialize it to 0 before that line.
[DH1,hh2]=contour(x,y,psi,10,'-k');
Variable psi is not defined at that point in the code. For debugging purposes we can use psi1 instead.
psi1=psi1+(Ai.*(r.^(-i+1)+h11)+(r.^(1./2).*besselk(i-1./2,r.*alpha)+h22).*Bi).*gegenbauerC(i,-1./2, cos(t));
That comes out as all zero, because Ai and Bi are zero.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by