MATLAB Examples

This is an example of how to create two overlapping waves in 3 dimension in MATLAB®.

Read about the quiver3 and fill3 functions in the MATLAB documentation.

For more examples, go to MATLAB Plot Gallery

% Create some x data
x = linspace(0, 4*pi, 30);

% Create two waves to plot
y = sin(x);
z = sin(x-pi);

% Plot the first wave in red and fill with color
u = zeros(size(x));
fill3(x, y, u, 'r', 'EdgeColor', 'r', 'FaceAlpha', 0.5)
hold on

% Add arrows for the first wave
quiver3(x, u, u, u, y, u, 0, 'r')

% Plot the first wave in blue and fill with color
fill3(x, u, z, 'b', 'EdgeColor', 'b', 'FaceAlpha', 0.5)

% Add the arrows for the second wave
quiver3(x, u, u, u, u, z, 0, 'b')

% Use equal axis scaling
axis square
daspect([1 1 1])
xlim([0 13])
ylim([-1 1])
zlim([-1 1])