필터 지우기
필터 지우기

how to animate graph from csv file?

조회 수: 4 (최근 30일)
Shwe
Shwe 2024년 1월 21일
댓글: Shwe 2024년 1월 22일
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.

채택된 답변

Walter Roberson
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
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?
Shwe
Shwe 2024년 1월 22일
currently i have 2023 Matlab.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by