My question is a possible duplicate of this: https://in.mathworks.com/matlabcentral/answers/296852-i-m-getting-the-error-as-matrix-dimensions-must-agree-at-line-no-20#answer_229522

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.

## Best Answer