How to collect it by using loop

1 view (last 30 days)
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 Comments
Stephen23
Stephen23 on 4 Dec 2018
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 on 4 Dec 2018
Thanks for guidance.
What may be done for using indexing for solving this?

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 4 Dec 2018
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 Comments
SYED AQEEL HAIDER
SYED AQEEL HAIDER on 4 Dec 2018
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!