- put them into one mat file.
- change the file extension to .txt.
- edit your question, click the paperclip button.
Help me to solve this
1 回表示 (過去 30 日間)
古いコメントを表示
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
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
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
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]
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!