save elements in a structure with matalb ?

1 visualización (últimos 30 días)
jiji hr
jiji hr el 20 de Jun. de 2016
Comentada: Shameer Parmar el 20 de Jun. de 2016
Hello, I have a 3x4 matrix, I want to implement this algorithm:
for each ligne compute the max value
store elements with value >= max/2 (for each ligne)
save this elements and correspending indices (i,j)
what I did is this :
%Filtrer les mauvaises correspondences en se basant sur la mesure de
%similarité.
i = 1;
for indVertexS = 1 : size(C,1)
maxi = max(C(indVertexS,:));
maxi = maxi/2;
j = 1;
for indVertexM = 1 : size(C,2)
if C(indVertexS,indVertexM) >= maxi
Cnew(i).corresp(j)= C(indVertexS,indVertexM);
Cnew(i).indS(j) = indVertexS ;
Cnew(i).indM(j) = indVertexM;
else
continue;
end
j = j+1;
end
i = i+1;
end
But the problem I encountered is that it includes incorrect values to (zeroes). and some indices are also incorrect (I get zeroes), and I don't understand where the error is ?
  2 comentarios
jiji hr
jiji hr el 20 de Jun. de 2016
I have found the solution, it was a bad palcement of the indix j, so all I have to do is to put it inside of the structure if :
if C(indVertexS,indVertexM) >= maxi
Cnew(i).corresp(j)= C(indVertexS,indVertexM);
Cnew(i).indS(j) = indVertexS ;
Cnew(i).indM(j) = indVertexM;
j = j+1;
end
and I don't need any more to use the function continue; I am sorry it seems that I have to pay more attention.
Shameer Parmar
Shameer Parmar el 20 de Jun. de 2016
It working fine with me..
my input was C = [1 5 3; 5 4 2; 7 8 3];
and Output was:
>> Cnew
Cnew =
1x3 struct array with fields:
corresp
indS
indM
>> Cnew(1)
ans =
corresp: [5 3]
indS: [1 1]
indM: [2 3]
>> Cnew(2)
ans =
corresp: [5 4]
indS: [2 2]
indM: [1 2]
>> Cnew(3)
ans =
corresp: [7 8]
indS: [3 3]
indM: [1 2]

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by