0.txt文件内容
txt文件中共有5000行三列内容,需要将两列内容使用matlab进行可视化。
1.matlab可视化
clc, clear;
data = readtable('spring_damper.txt');
t = linspace(0,50,5000)';
%生成5000行一列数据
y=data{:,2};
dy=data{:,3};
hold on;
plot(t,y);
plot(t,dy);
title("弹簧运动方程y和y'C++")
xlabel('t/s', 'Interpreter', 'Latex')
ylabel('', 'Interpreter', 'Latex')
legend('RK4 y', "RK4 y'", 'Location', 'Best')
将txt文件和m文件放在同一目录下。