[SOLVED]: I'm getting the error "Array dimensions must match"
6 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
the cyclist
on 7 Jan 2021
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 Comments
More Answers (0)
See Also
Categories
Find more on Geometric Transformation and Image Registration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!