save elements in a structure with matalb ?

1 次查看(过去 30 天)
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 个评论
jiji hr
jiji hr 2016-6-20
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 2016-6-20
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]

请先登录,再进行评论。

回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by