
Plotting figures with user defined functions
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to plot an image of a train sketch using a rectangle function and a circle function but I don't understand why it's not giving the right output.

Here's my code:
plotrectangle(1, 1.5, 3, 2)
hold all;
plotrectangle(3, 3.5, .5, .5)
plotcircle(2.5,4,1)
plotcircle(1.5, 4.5, 2)
plotcircle(1.5,1,2)
plotcircle(3.5,1,2)
function [] = plotrectangle(x, y, l, w)
figure;
rectangle('Position', [x y l w]);
axis( [0 10 0 10] )
end
function [] = plotcircle(c1,c2,r)
t = 0:0.0001:2*pi;
x = r*cos(t)+c1;
y = r*sin(t)+c2;
plot(x, y);
axis( [0 5 0 5 ] )
end
0 commentaires
Réponses (1)
Matt J
le 28 Sep 2019
Modifié(e) : Matt J
le 28 Sep 2019
For some reason, you've given circle radii that are all off by a factor of 6.
plotrectangle(1, 1.5, 3, 2)
hold on
plotrectangle(3, 3.5, .5, .5)
plotcircle(2.5,4.5,1)
plotcircle(1.5, 4.5, 2)
plotcircle(1.5,1,3)
plotcircle(3.5,1,3)
hold off
axis equal
function [] = plotrectangle(x, y, l, w)
rectangle('Position', [x y l w]);
end
function [] = plotcircle(c1,c2,r)
r=r/6;
t = 0:0.0001:2*pi;
x = r*cos(t)+c1;
y = r*sin(t)+c2;
plot(x, y);
end

0 commentaires
Voir également
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!