Need to store some results of a function in a matrix

조회 수: 8 (최근 30일)
Daniel Alcaraz
Daniel Alcaraz 2017년 5월 31일
댓글: Daniel Alcaraz 2017년 6월 1일
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에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by