How to collect it by using loop

1 次查看(过去 30 天)
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 个评论
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