how to animate graph from csv file?

8 Ansichten (letzte 30 Tage)
Shwe
Shwe am 21 Jan. 2024
Kommentiert: Shwe am 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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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 Kommentare
Walter Roberson
Walter Roberson am 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 am 22 Jan. 2024
currently i have 2023 Matlab.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by