Animation of Matrix or .mat Data
Show older comments
Hello,
i have simulaiton data as a Matrix or .mat data and i want to make an animation of them. The simulation is with different initial conditions so I want an Animation of all of these at the same time. It's about a state space model.
Thank you for your help.
3 Comments
Hassaan
on 15 Jan 2024
- Load your simulation data: If you have your simulation data in a .mat file, load it using the load function or read the data from a matrix.
- Create a figure: Initialize a figure to display the animation.
- Loop through the different initial conditions: Use a for loop to iterate through your simulation data for different initial conditions.
- Plot the data for each initial condition: Inside the loop, plot the data corresponding to each initial condition using functions like plot, scatter, or any other appropriate visualization method.
- Update the figure: After plotting each set of data, use the drawnow function to update the figure and display the new data.
- Pause for a specified duration: Use the pause function to control the animation speed by specifying the time between frames.
% Load your simulation data or create a sample data matrix
% Replace 'simulation_data.mat' with your data file or matrix
load('simulation_data.mat');
% Create a figure
figure;
title('Simulation Animation');
% Define the time step and animation duration
time_step = 0.1; % Adjust this based on your simulation time step
animation_duration = 5; % Total animation duration in seconds
% Loop through different initial conditions
for initial_condition = 1:size(simulation_data, 3)
% Extract data for the current initial condition
data = simulation_data(:, :, initial_condition);
% Plot the data (assuming it's a 2D state-space representation)
plot(data(:, 1), data(:, 2), 'b-'); % Adjust the plot style as needed
% Set axis limits based on your data
xlim([min(data(:, 1)) max(data(:, 1))]);
ylim([min(data(:, 2)) max(data(:, 2))]);
% Update the figure
drawnow;
% Pause for a specified duration to control animation speed
pause(time_step);
% Clear the current plot to prepare for the next frame
clf;
end
simulation_data is assumed to be a 3D matrix where each slice along the third dimension represents the simulation data for a different initial condition. You would replace 'simulation_data.mat' with the path to your actual data file or data matrix. Adjust the plot style, axis limits, time step, and animation duration as needed for your specific simulation data.
------------------------------------------------------------------------------------------------------------------------------------------------
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.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
FOB
on 16 Jan 2024
Benjamin Thompson
on 20 Jan 2024
If you type "doc fanimator" in MATLAB there are a few examples. For more help attach examples of what you have done so far and ask specific questions to get help with improving it.
Answers (1)
Muskan
on 23 Jan 2024
0 votes
Hi,
As per my understanding, you can use the MATLAB function "fanimator" to create an animation object.
Please refer to the below documentation for more information:
You can also refer to the following documentation that illustrates various examples related to animation of an object:
I hope this helps!
Categories
Find more on Marine and Underwater Vehicles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!