4 views (last 30 days)

Hello everyone

I want to vectorize the following code to reduce operation time. Can you guys help me out?

thanks

% X is a double matrix

s=size(X);

RepSol=repmat(X,2,2);

% Y is a binary matrix

Y=repmat(Y,2,2);

% Preallocation

p=zeros(s);

for m=1:s(1)

for n=1:s(2)

for i=1:s(1)

for j=1:s(2)

if RepSol(i,j)==RepSol(m+i-1,n+j-1)

p(m,n)=p(m,n)+Y(i,j)*Y(m+i-1,n+j-1);

end

end

end

end

end

darova
on 10 Sep 2019

IS it correct?

for m=1:s(1)

for n=1:s(2)

cond = RepSol(1:s(1),1:s(2)) == RepSol((1:s(1))+m-1,(1:s(2))+n-1);

% cond = X - RepSol((1:s(1))+m-1,(1:s(2))+n-1);

P = Y(1:s(1),1:s(2)) .* Y((1:s(1))+m-1,(1:s(2))+n-1);

res = cond .* P;

p(m,n) = sum(res(:));

end

end

aliaqa aliaqa
on 17 Sep 2019

darova
on 17 Sep 2019

Unfortunately is explains nothing

The script does the follwoing if i understood correctly:

Rik
on 17 Sep 2019

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.