Help me to solve this

조회 수: 1 (최근 30일)
Ad
Ad 2017년 5월 13일
댓글: Ad 2017년 5월 15일
I am very new to matlab and working on image processing in order to detect the object.
I have an Index matrix I: 10 11 12 13 14 15 16 20 21 22 23 24 26 29 30 31 32 37 39 40 Highestvalue, H=13
M=[]; % THIS IS NOT THE FULL CODE
for i=1
for j=1:ILength
if((Distance(H,I(j))<=10)&& (adjMatrix(H,I(j))~=0))
M=[M,j];
end
end
end
I got the result like this: "Result" or M for H 13= 12,13,14.
Expected result is "12 13 14 15 16 20 21 22 23 24 26 29 30 31 32"
Question: How to perform it again for each and every value in the "Result" with no repetitions? For example, again I need to calculate adjacency and distance for 14,12. (For 14, the expected value is 15,16,20) and then for 16, 20 and so on.
Thanks in advance
  댓글 수: 3
Star Strider
Star Strider 2017년 5월 13일
‘% THIS IS NOT THE FULL CODE’
... that appears to be missing an assignment for ‘HS’ and ‘Result’.
‘H’ is doing as it should, and returning a 3-element vector for row ‘H’:
RowH = [Distance(H,:); adjMatrix(H,:)];
RowHi = RowH(1,:)<=10 & RowH(2,:)~=0;
RowHi =
1×48 logical array
0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Your code works as it should. There is no problem, unless you did not write your code correctly.
We have no idea of knowing what you want to do unless you tell us.
MrsBellamy
MrsBellamy 2017년 5월 13일
편집: MrsBellamy 2017년 5월 13일
The code that you posted will not "return" [12,13,14] but the indices [3,4,5].
It must be M = [M,I(j)];
I imported your data and for H=13, I indeed get the result M=[12,13,14]. For H=14 however, I get M=[13,14,15] and not [15,16,20]. You might wanna check this again?

댓글을 달려면 로그인하십시오.

채택된 답변

MrsBellamy
MrsBellamy 2017년 5월 13일
You can solve the problem by introducing the array "usedIndices" which collects all values of H that have been used. "newIndices" are values that are contained in M, but have not been used yet.
M=[];
usedIndices=[];
newIndices=[13];
while ~isempty(newIndices)
for i=length(newIndices)
H=newIndices(i);
for j=1:length(I)
if((Distance(H,I(j))<=10)&& (adjMatrix(H,I(j))~=0))
M=[M,I(j)];
end
end
M = unique(M);
usedIndices = [usedIndices, H];
end
newIndices = setdiff(M,usedIndices);
end
Which indeed yields:
M = [12,13,14,15,16,20,21,22,23,24,26,30,31,32]
  댓글 수: 1
Ad
Ad 2017년 5월 15일
@MrsBellamy, Thank you so much for the support.
I have one doubt.You have directly assigned highest value to new indices.right?
newIndices=[13];

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by