save elements in a structure with matalb ?
Show older comments
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 Comments
jiji hr
on 20 Jun 2016
Shameer Parmar
on 20 Jun 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]
Answers (0)
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!