how to plot a smily in matlab

To plot a smiley face in matlab, we can use the plot function to plot different circles and lines. Here's an example code:

main.m
% create a circle for the face
theta = linspace(0, 2*pi);
x = 3*cos(theta);
y = 3*sin(theta);

% plot the face
plot(x,y,'LineWidth',2,'Color','black');
hold on;

% create circles for the eyes
theta_2 = linspace(0, 2*pi);
x_2 = 0.75*cos(theta_2) - 1.5;
y_2 = 0.75*sin(theta_2) + 0.75;
x_3 = 0.75*cos(theta_2) + 1.5;
y_3 = 0.75*sin(theta_2) + 0.75;

% plot the eyes
plot(x_2,y_2,'LineWidth',2,'Color','black');
plot(x_3,y_3,'LineWidth',2,'Color','black');

% create arcs for the mouth
theta_3 = linspace(-pi/4, pi/4);
x_4 = 2*cos(theta_3);
y_4 = -0.75*sin(theta_3) - 1.5;
x_5 = 2*cos(theta_3);
y_5 = -0.75*sin(theta_3) - 1.5;

% plot the mouth
plot(x_4,y_4,'LineWidth',2,'Color','black');
plot(x_5,y_5,'LineWidth',2,'Color','black');
732 chars
31 lines

This will create a smiley face with the following plot:

smiley

Note that we used the hold on function to plot all circles and lines on the same plot. The lineWidth and Color parameters are used to set the thickness and color of the lines.

gistlibby LogSnag