how to save variables with increasing number for result of cross correlation images.

i have problem to do loop for cross correlation of images. from coding, it can displayed the result without being overlap. but i dont know how to save the same result at workspace using different number so that i can construct the rectangle for color indicator due to result of cross correlation. what i have now,
i = 1:10 ( i have 10images to be cross correlation with template image)
c = result of cross correlation.
%displayed on command window
c 1
c 2
until c10 %because have 10 images.
but at woskspace, the value of c is c10, its overlapping from first image until last image. so i cannot construct the rectangle. i have tried using eval method, but i dont know how to relate it with my calculation of cross correlation. i hope anyone can help me.

Answers (1)

The result of cross-correlating two images (matrices) is normally another matrix, not a scalar value.
Regardless, the easiest way to store the results of a for loop is to use a matrix of a higher dimension than your result. If the results are scalar, store these in a 1d array, if they are a vectors, store these in a 2d matrix, and if they're images store your images in a 3d matrix. That is assuming that all the results have the same size. If not, use a cell array instead.
numimages = 10; %number of images to process
c = zeros(10, 20, numimages); %replace 10 and 20 by whatever size your crosscorrelation create
for imgidx = 1:numimages
c(:, :, imgidx) = resultofcrosscorrelation;
end
Or using a cell array:
numimages = 10; %number of images to process
c = cell(numimages, 1);
for imgidx = 1:numimages
c{imgidx} = resultofcrosscorrelation;
end

4 Comments

Hi, thank you for feedback. but i am so sorry, i am totally not understand. I am is beginner in matlab and i have project for my final project for graduate. my problem is, i want to save variable "c" in workspace as c1. c2. c3.. until c10.
there is a loop for cross correlation, when the coding do their things, it will save as c1, then loop for second image, then save for c2.. until c10. the problem is, the value of c is overlap. so what you provided is the solution ? because sorry I m not understand.
While it is possible to create variables c1, c2, etc. in a loop, it is a really bad idea. The good way of doing it is as I have said to use an array.
I don't know what your c is (not just the result of a cross-correlation of two images for sure), but it looks like it's just a scalar (i.e. one number). So, to solve your problem:
numimages = 10;
c = zeros(numimages, 1);
for imgidx = 1:numimages
c(imgidx) = result of cross correlation;
end

Sign in to comment.

Asked:

on 14 May 2015

Commented:

on 19 May 2015

Community Treasure Hunt

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

Start Hunting!