Need to store some results of a function in a matrix

1 次查看(过去 30 天)
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.

回答(1 个)

Matthew Eicholtz
Matthew Eicholtz 2017-5-31
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 个评论
Daniel Alcaraz
Daniel Alcaraz 2017-6-1
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by