how to animate graph from csv file?

8 visualizaciones (últimos 30 días)
Shwe
Shwe el 21 de En. de 2024
Comentada: Shwe el 22 de En. de 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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de En. de 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 comentarios
Walter Roberson
Walter Roberson el 22 de En. de 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 el 22 de En. de 2024
currently i have 2023 Matlab.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Animation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by