How to collect it by using loop

조회 수: 4 (최근 30일)
SYED AQEEL HAIDER
SYED AQEEL HAIDER 2018년 12월 4일
댓글: SYED AQEEL HAIDER 2018년 12월 4일
In response of statement
[J,K] = find(Image);
I have got J and K of size [14,1]
Now I want to locate
R1 = [J(1), K(1)]
R2 = [J(2), K(2)] and so on till R14 = [J(14), K(14)]
How to complete this task using loop?
  댓글 수: 2
Stephen23
Stephen23 2018년 12월 4일
You tagged this question with "changing variable name for each iteration", but it is important to learn that magically changing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know why:
The MATLAB documentation and all experienced MATLAB users reccomend using indexing. Indexing is neat, simple, very efficient, and easy to debug. Unlike what you are trying to do.
SYED AQEEL HAIDER
SYED AQEEL HAIDER 2018년 12월 4일
Thanks for guidance.
What may be done for using indexing for solving this?

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

채택된 답변

madhan ravi
madhan ravi 2018년 12월 4일
Don't name the variable dynamically use cell instead
R=cell(1,14); % preallocation
for i=1:14
R{i}=find(image);
end
celldisp(R)
  댓글 수: 3
madhan ravi
madhan ravi 2018년 12월 4일
size(J,1)
SYED AQEEL HAIDER
SYED AQEEL HAIDER 2018년 12월 4일
I am having these points
R1 = [387, 144]
R2 = [392, 145]
R3 = [400, 147]
R4 = [405, 150]
R5 = [393,152]
R6 = [402, 158]
R7 = [395, 168]
R8 = [381,180]
R9 = [492, 334]
R10 = [293, 354]
R11 = [291, 355]
R12 = [284, 356]
R13 = [288, 356]
R14 = [438, 688]
Now, I have to calculate mean of the neighboring points. There are four clusters of white dots. R1, R2, R3, R4, R5, R6, R7 and R8 in cluster1; R9 in cluster2; 10, R11, R12, R13 in cluster3 and R14 in cluster4. How may I group these points automatically and calculate the mean of culter1 and 3. Kindly mention. I have tried 'kmedoid' but it is not working for me.

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

추가 답변 (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