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

4 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

the cyclist
the cyclist il 7 Gen 2021
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.

Più risposte (0)

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by