animate_fields(dim, varargin)
When working with signals or fields that vary in time, it is often useful to visualize those fields using animations. This function takes 1-dimension or 2-dimension time dependant variables and animates them in Matlab. The user is given media controls and the option to save the animation as a video file for later playback when Matlab isn't available.
animate_fields(dimension,'field name',field) will animate the "field" of a certain "dimension".
For example, the simplest case being a 1D voltage signal:
animate_fields(1,'Voltage',V)
where V is a matrix in which each row represents the voltage across the spatial domain at a certain timestep, i.e. V(:,k) will be the voltage at timestep k.
For 2D fields:
animate_fields(2,'E field',E)
where E(:,:,k) will be the 2D field at timestep k.
Additionally, any number of fields can be animated side by side.
A number of options can be controlled through the function using parameters, such as the ability to manually set the axis sizes, number of frames per second, minimum and maximum amplitudes, grid and colormap.
A more complete example to plot trigonometric functions may look like this:
animate_fields(1,'domain',domain,'grid','on', 'save','file.avi',...
'Sine',sine,...
'Cosine',cosine,...
'Tangent',tangent, 'min_amplitude',-1, 'max_amplitude',1, 'grid','off',...
'Secant',secant, 'min_amplitude',-2, 'max_amplitude',2)
This is my first submission so please feel free to email me with any improvements you might like to share!
引用格式
Daniel Simmons (2024). animate_fields(dim, varargin) (https://www.mathworks.com/matlabcentral/fileexchange/46216-animate_fields-dim-varargin), MATLAB Central File Exchange. 检索来源 .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
- MATLAB > Graphics > 2-D and 3-D Plots > Animation > Movie >
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!