plot a smiley face in matlab

To plot a smiley face in MATLAB, you can use the scatter plot function and plot a sequence of dots with appropriate colors and sizes. Here's an example:

main.m
% Define the coordinates and colors for the dots
x = [0 0.2 0.4 0.6 0.8 1];
y = [0.5 0.7 0.8 0.8 0.7 0.5];
c = [1 0.8 0.2; 1 0.8 0.2; 1 0.8 0.2; 1 0.8 0.2; 1 0.8 0.2; 0.5 0.5 1];
s = [300 300 300 300 300 1000];

% Plot the dots
scatter(x, y, s, c, 'filled');
hold on

% Add the eyes
eye_x = [0.3 0.7];
eye_y = 0.7;
eye_c = [0.2 0.2 0.2];
eye_s = 150;
scatter(eye_x, eye_y, eye_s, eye_c, 'filled');

% Add the mouth
theta = 0:pi/20:pi;
mouth_x = 0.5 + 0.2*cos(theta);
mouth_y = 0.2*sin(theta) + 0.4;
mouth_c = [0.8 0.2 0.2];
mouth_s = 100;
scatter(mouth_x, mouth_y, mouth_s, mouth_c, 'filled');

% Set the axis and figure properties
axis equal
axis off
set(gcf, 'color', [0.8 0.8 1])
683 chars
30 lines

This code produces the following smiley face plot:

Smiley Face Plot

related categories

gistlibby LogSnag