[SOLVED]: I'm getting the error "Array dimensions must match"

조회 수: 5 (최근 30일)
Shashank V.M.
Shashank V.M. 2021년 1월 7일
편집: Shashank V.M. 2021년 1월 7일
But I have trouble understanding the accepted answer.
I am trying to perform element wise multiplication of 2 matrices.
This is the error I am getting:
Array dimensions must match for binary array op.
Error in Simplifed_pcnn>local_pcnn (line 22)
U = F.*(ones(sz) + Beta.* L);
Error in Simplifed_pcnn (line 2)
K = local_pcnn(A);
Here is the code I used, it is for PCNN based image segmentation. The operation is performed Num times, that is why for loop is used :
S = imread('cucumber_hsv.jpg');
K = local_pcnn(A);
imshow(K)
function Y = local_pcnn(S)
lambda = 0.9;
V_T = 100.0;
Num = 100;
W = [0.5 1 0.5;1 0 1;0.5 1 0.5];
m = size(S);
sz = m(:,1:2);
Beta = zeros(sz) + 0.1;
F = zeros(sz);
L = F;
Y = F;
U = F;
T = ones(sz);
S = im2double(S);
for n = 1:Num
F = S;
L = conv2(Y, W);
U = F.*(ones(sz) + Beta.* L);
Y = double(U>T);
T = lambda * T + V_T * Y;
end
end
Beta, F and U are of the same size, but I am getting an error. I am unable to figure out the reason for the error.

채택된 답변

the cyclist
the cyclist 2021년 1월 7일
I recommend that you use the debugger to investigate. Specifically, set a breakpoint at the line
U = F.*(ones(sz) + Beta.* L);
and you will see that L is actually the culprit. (At least it was for an image I tried.)
It has two additional columns, compared to the other variables.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by