How can I illustrate a sinusoidal plane wave in MATLAB?
Afficher commentaires plus anciens

I am able to plot the red sine wave and the the blue lines (without the arrows) but I am unable to plot the planar vector fields.
How can I replicate the above image in a MATLAB figure?
Réponse acceptée
Plus de réponses (1)
% Define the domain
x = linspace(-2*pi, 2*pi, 100);
z = linspace(-2, 2, 20);
[X, Z] = meshgrid(x, z);
% Define the wave
y = sin(X);
% Create a new figure
figure;
% Plot the sinusoidal wave
surf(X, y, Z, 'FaceColor', 'red', 'EdgeColor', 'none');
alpha 0.5; % Making the surface semi-transparent
hold on;
% Plot the lines (without arrows)
for i = 1:size(Z, 1)
plot3(X(i, :), y(i, :), Z(i, :), 'b');
end
% Now let's add the planar vector fields using quiver3
[U, V, W] = deal(zeros(size(X))); % Preallocate U, V, W for quiver3
V = ones(size(X)); % Vectors point in the positive y-direction
% Create a grid in the y-direction for the vectors
Y = -2:0.5:2;
% Plot the vectors on each plane
for i = 1:length(Y)
quiver3(X, Y(i)*ones(size(X)), Z, U, V, W, 'k', 'MaxHeadSize', 0.005);
end
% Set the view angle
view(30, 45);
% Labels and title
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Sinusoidal Plane Wave with Planar Vector Fields');
% Remove the ticks
set(gca, 'XTick', [], 'YTick', [], 'ZTick', []);
% Remove the box around the plot
box off;
% Keep the axis aspect ratio normal
axis normal;
hold off;
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
Catégories
En savoir plus sur Graphics Object Properties dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

