필터 지우기
필터 지우기

save elements in a structure with matalb ?

조회 수: 1 (최근 30일)
jiji hr
jiji hr 2016년 6월 20일
댓글: Shameer Parmar 2016년 6월 20일
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에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by