# Need to store some results of a function in a matrix

2 views (last 30 days)
Daniel Alcaraz on 31 May 2017
Commented: Daniel Alcaraz on 1 Jun 2017
for a=4:5
[A]=correlacion(v7(a).imagen,v3(i).imagen)
end
And this is the function that I'm using
function [A]=correlacion(Ipat, Iref)
for i=1:20
% Trobar la correlacio normalitzada entre el patro i la imatge de referencia:
Icorr = normxcorr2(Ipat,Iref);
[posY, posX] = find(abs(Icorr) == max(max(Icorr)));
% Correccio de la posicio fent servir la mida del patro:
posXreal= posX - (size(Ipat,2)-1)/2;
posYreal= posY - (size(Ipat,1)-1)/2;
A(i,:)=[posXreal' posYreal'];
end
end
The idea is to store the results in a matrix A, but the program forget the numbers that has created.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Answers (1)

Matthew Eicholtz on 31 May 2017
If I understand your problem correctly, the values stored in A when a=4 are being replaced by the new values generated by your function when a=5. There are many potential remedies to this problem. One solution might be to use separate variables for each value of a:
A4 = correlacion(v7(4).imagen,v3(i).imagen);
A5 = correlacion(v7(5).imagen,v3(i).imagen);
This works well when a=4:5, but maybe not if a had more values. Suppose a=1:100; then I would suggest trying a cell array:
A = cell(100,1);
for a=1:100
A{a} = correlacion(v7(a).imagen,v3(i).imagen)
end
##### 1 CommentShowHide None
Daniel Alcaraz on 1 Jun 2017
Thanks for your answer, I've just found the solution. Finally I did something like your method:
for i=1:20 [posXreal posYreal]=correlacion(i6(2).imagen,i3(i).imagen) A1(i,:)=posXreal end

Sign in to comment.

### Categories

Find more on Matrix Indexing in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by