Freeman chain code object plot
Afficher commentaires plus anciens
I am trying to generate an image based on an initial x and y coordinates and a freeman chain code as shown in code below but it does not plot anything, any idea why?
Code:

cc = '03222232232232332334435455455556555545555555454545454454445444444444344444344434443444344344344434434434434434434344343443434343443434343434434343434343434334343434343343434334343343433434334334343343343343343343343343343343343343334334334333433433433343334334333433343333433343333433334333334333334333333433333333343333333333333333333333333333333333333323333333233333323333323333233323332333233323323323323323323323233233232323323232323232332232323232323223232322323223232232232232232223223222322232222322232222232222222322222222232222222222222222221221221221221221212121212121212112121212121212121212121212121223343343343343433433556565556556565565565655655656556556565565565565555655565556565565565565565656556565655656566565656566565665665656656665665665666566656666566665666665666666566666666665666666666666666666666666666666676666666666766666667666667666667666676667666766676667667666766766766766767667667676676767667676767676767676767676767767677676767767767767767767767776776777767776777776777777677777777777777776778777777777778777777787777877778777877787778778778778778778778778787787877878787787878787787878787878787787878787878877887878787878788787878878787887878878788787887887887887887878887887887887888788788878887888878887888878888788888788888878888888788888888887888888888888888888888888888818888888888188888818888818888188818881888188188188188181881818188181818181811818181181181181181181111811111181111111111122222'
sz = 25;
c = 'r';
x = 100;
y = 50;
for i = 1 : strlength(cc)
if cc(i) == 0
x = x+1;
scatter(x,y,sz,c,'filled')
elseif cc(i) == 1
x = x+1;
y = y+1;
scatter(x,y,sz,c,'filled')
elseif cc(i) == 2
y = y+1;
scatter(x,y,sz,c,'filled')
elseif cc(i) == 3
x = x-1;
y = y+1;
scatter(x,y,sz,c,'filled')
elseif cc(i) == 4
x = x-1;
scatter(x,y,sz,c,'filled')
elseif cc(i) == 5
x = x-1;
y = y-1;
scatter(x,y,sz,c,'filled')
elseif cc(i) == 6
y = y-1;
scatter(x,y,sz,c,'filled')
elseif cc(i) == 7
x = x+1;
y = y-1;
scatter(x,y,sz,c,'filled')
end
end
1 commentaire
Nolan Canegallo
le 24 Jan 2021
Modifié(e) : Nolan Canegallo
le 24 Jan 2021
Firstly, why are there 8's in the input string? What do they correspond to?
Secondly, the reason the points are not staying is because you need to put a
hold on
after you create your figure so that repeated calls to scatter will be added to the plot instead of being overwritten.
Thirdly, if you are not animating your chain, then saving the data points in a variable and then plotting all at once could save time/efficiency.
Finally, if possible, switching the input from a string to a column or row vector of integers would be beneficial.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Entering Commands dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
