how to animate graph from csv file?

6 views (last 30 days)
Shwe
Shwe on 21 Jan 2024
Commented: Shwe on 22 Jan 2024
hi
i have force vs time data with csv file format and ploted on the graph. i want to know how to write script for this graph and how to make animation of the plot.

Accepted Answer

Walter Roberson
Walter Roberson on 21 Jan 2024
M = readmatrix('12012024_1.csv');
time = M(:,1);
F1 = M(:,2); F2 = M(:,3); F3 = M(:,4); F4 = M(:,5); F5 = M(:,6); F6 = M(:,7);
h1 = animatedline([], [], 'DisplayName', 'force 1');
hold on
h2 = animatedline([], [], 'DisplayName', 'force 2');
h3 = animatedline([], [], 'DisplayName', 'force 3');
h4 = animatedline([], [], 'DisplayName', 'force 4');
h5 = animatedline([], [], 'DisplayName', 'force 5');
h6 = animatedline([], [], 'DisplayName', 'force 6');
legend show
for K = 1 : length(time)
now = time(K);
addpoints(h1, now, F1(K));
addpoints(h2, now, F2(K));
addpoints(h3, now, F3(K));
addpoints(h4, now, F4(K));
addpoints(h5, now, F5(K));
addpoints(h6, now, F6(K));
pause(0.05);
end
  3 Comments
Walter Roberson
Walter Roberson on 22 Jan 2024
I tested... the above code works fine for me.
Though I might suggest coloring the lines
M = readmatrix('12012024_1.csv');
time = M(:,1);
F1 = M(:,2); F2 = M(:,3); F3 = M(:,4); F4 = M(:,5); F5 = M(:,6); F6 = M(:,7);
h1 = animatedline([], [], 'Color', 'r', 'DisplayName', 'force 1');
hold on
h2 = animatedline([], [], 'Color', 'g', 'DisplayName', 'force 2');
h3 = animatedline([], [], 'Color', 'b', 'DisplayName', 'force 3');
h4 = animatedline([], [], 'Color', 'c', 'DisplayName', 'force 4');
h5 = animatedline([], [], 'Color', 'm', 'DisplayName', 'force 5');
h6 = animatedline([], [], 'Color', 'k', 'DisplayName', 'force 6');
legend show
for K = 1 : length(time)
now = time(K);
addpoints(h1, now, F1(K));
addpoints(h2, now, F2(K));
addpoints(h3, now, F3(K));
addpoints(h4, now, F4(K));
addpoints(h5, now, F5(K));
addpoints(h6, now, F6(K));
pause(0.01);
end
Which MATLAB release are you using?
Shwe
Shwe on 22 Jan 2024
currently i have 2023 Matlab.

Sign in to comment.

More Answers (0)

Categories

Find more on Animation 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!