how to create a figure window with axes in matlab

You can create a figure window with axes in MATLAB using the figure and axes functions. The figure function creates a new figure window and the axes function creates axes within the figure window.

Here's an example code:

main.m
x = linspace(0, 2*pi, 100);
y = sin(x);

figure; % create a new figure window
plot(x, y); % plot a sine wave
xlabel('x');
ylabel('y');
title('Sine Wave');

% create a new set of axes within the same figure window
axes('position', [0.6 0.6 0.25 0.25]);
plot(x, cos(x)); % plot a cosine wave
xlabel('x');
ylabel('y');
title('Cosine Wave');
338 chars
16 lines

In this example, we first create a new figure window using the figure function. Then, we plot a sine wave using the plot function.

Next, we use the axes function to create a new set of axes within the same figure window. The 'position' parameter specifies the position and size of the new axes. Finally, we plot a cosine wave on the new axes using the plot function.

We add labels and a title to each plot using xlabel, ylabel, and title functions.

The resulting figure window with two sets of axes is shown below:

figure window with axes

related categories

gistlibby LogSnag