Vectorize for loop: corr2(A(:,:,i),B(:,:,i))
Show older comments
Hi, I am trying to accelerate a function and am unable to perform this myself, so I am hoping for your help.
I have a set of 10.000 small images (64x64), and I need to calculate the correlation coefficient for each of these images. This is the code:
clear all
clc
close all
A=rand(64,64,10000);
B=rand(64,64,10000);
corr_result=zeros(1,1,size(A,3));
tic
for i=1:size(A,3)
corr_result(i)=corr2(A(:,:,i),B(:,:,i));
end
toc
I found this, it results in a 64x64x1 matrix, but I need a 1x1x10000 matrix.... Thanks for your input!!
5 Comments
Deepak Gupta
on 3 Dec 2020
Edited: Deepak Gupta
on 3 Dec 2020
I ran this code and got a matrix of size 64x64x10000 matrix. Don't know what's the problem.
Ameer Hamza
on 3 Dec 2020
but I need a 1x1x10000 matrix
Can you explain how? Shouldn't it be 64x64x10000?
William Thielicke
on 3 Dec 2020
Edited: William Thielicke
on 3 Dec 2020
Ameer Hamza
on 3 Dec 2020
I think this is already as efficient as it can get in MATLAB. After JIT optimizations, for-loops are not as slow as one might think.
William Thielicke
on 3 Dec 2020
Accepted Answer
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
