how to animate graph from csv file?
8 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Walter Roberson
2024-1-21
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 个评论
Walter Roberson
2024-1-22
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?
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!