How to collect it by using loop

4 Ansichten (letzte 30 Tage)
SYED AQEEL HAIDER
SYED AQEEL HAIDER am 4 Dez. 2018
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 Kommentare
Stephen23
Stephen23 am 4 Dez. 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 am 4 Dez. 2018
Thanks for guidance.
What may be done for using indexing for solving this?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

madhan ravi
madhan ravi am 4 Dez. 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 Kommentare
madhan ravi
madhan ravi am 4 Dez. 2018
size(J,1)
SYED AQEEL HAIDER
SYED AQEEL HAIDER am 4 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by