Need to store some results of a function in a matrix

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (1)

Matthew Eicholtz
Matthew Eicholtz il 31 Mag 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 Commento
Daniel Alcaraz
Daniel Alcaraz il 1 Giu 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

Accedi per commentare.

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by