Help with "for" loop

Associate
Joined
28 Jul 2003
Posts
1,987
Location
The Moon
Hello,

I am wanting to create a for loop in Matlab which will allow me to cycle an image through various sizes. The code to do this is imresize(image, scaling factor)

I wrote my loop as follows but it does not work;

for n = 0.1:0.1:1
h = imresize(image1, n)
c = normxcorr2(image2,h)
end

I am wanting to scale image1 through various sizes, correlating it with a larger image each time in order to find the best match. However this is not happening, I know I have written the loop incorrectly but I cannot see where exactly.
 
It should have been c = normxcorr2(h,image2). I think I need to do something like this:

for i = 0.1:0.1:1
h(i) = imresize(image1,i);
c(i) = normxcorr2(h,image2);
end
 
When I use the original loop I posted, I got this error, Subscript indices must either be real positive integers or logicals.
 
you dont have any subscript indices in your original post.

in
Code:
for i = 0.1:0.1:1
h(i) = imresize(image1,i);
c(i) = normxcorr2(h,image2);
end

I missed that you cant use i in c(i) since i = 0.1 0.2 0.3 etc. which would give you that error message.

So how do I get around it?
 
Back
Top Bottom