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