amjay
amjay

Reputation: 11

How to draw a circle in matlab with different range in X and Y axis

I would like draw a circle in matlab. However, my data X and Y have different range axis. I suspected that my values of X and Y have different range. Could anyone advice me on how to improve the code?

%% Data set
    fData = [   3.6     79
            1.8     54
            3.333   74
            2.283   62
            4.533   85
            2.883   55
            4.7     88
            3.6     85
            1.95    51
            4.35    85
            1.833   54
            3.917   84
            4.2     78
            1.75    47
            4.7     83
            2.167   52
            1.75    62
            4.8     84
            1.6     52
            4.25    79
            1.8     51
            1.75    47
            3.45    78
            3.067   69
            4.533   74
            3.6     83
            1.967   55
            4.083   76
            3.85    78
            4.433   79
            4.3     73
            4.467   77
            3.367   66
            4.033   80
            3.833   74
            2.017   52
            1.867   48
            4.833   80
            1.833   59
            4.783   90  ]

[n,dim]=size(fData);
rng(1);
idx = randsample(n,2)
X = fData(~ismember(1:n,idx),:); % Training data
Y = fData(idx,:) 

for j = 1:length(Y)
     c = Y(j,:);
     pos = [c-r 2*r 2*r];
     rectangle('Position',pos,'Curvature',[1 1])
     %axis equal
end

How to make the both circle in the image become a perfect circle? Thank you

Upvotes: 0

Views: 114

Answers (1)

Ash
Ash

Reputation: 4718

What you need to do is set the aspect ratio you want for your data, replacing the %axis equal line in you code with

daspect([1 1 1])

should do the job, as you can see in this example obtained with your code:

example with your code

Upvotes: 1

Related Questions