How to read and plot a txt file

65 views (last 30 days)
Jose Jaquez
Jose Jaquez on 10 Nov 2023
Edited: Voss on 10 Nov 2023
I have this text file with time stamps and with values that I am trying to plot. I am not well versed in MatLab to even begin writing a code.

Accepted Answer

Voss
Voss on 10 Nov 2023
filename = 'Data1.txt';
T = readtable(filename)
T = 73×2 table
Var1 Var2 ____________ _______ 11:26:42.028 -178.39 11:26:42.126 175.5 11:26:42.265 -170.07 11:26:42.345 -172.13 11:26:42.428 179.11 11:26:42.526 179.7 11:26:42.629 177.88 11:26:42.759 169.8 11:26:42.849 161.06 11:26:42.945 -177.34 11:26:43.068 -170.62 11:26:43.146 -172.11 11:26:43.278 -177.71 11:26:43.362 173.86 11:26:43.451 168.34 11:26:43.555 170.14
plot(T.(1),T.(2))
  3 Comments
Jose Jaquez
Jose Jaquez on 10 Nov 2023
Wait nevermind, I forgot to edit it and delete the arrows, Thank you!!
Voss
Voss on 10 Nov 2023
Edited: Voss on 10 Nov 2023
You're welcome!
You can avoid deleting the arrows from the text file, if that's more convenient. The file is read just fine by readtable, so all you have to do is plot with the 3rd column instead of the 2nd:
filename = 'Data2.txt';
T = readtable(filename)
T = 86×3 table
Var1 Var2 Var3 ____________ ______ _______ 10:18:28.544 {'->'} -170.58 10:18:28.672 {'->'} -155.68 10:18:28.761 {'->'} -173.08 10:18:28.863 {'->'} 178.71 10:18:28.949 {'->'} 174.53 10:18:29.093 {'->'} 169.34 10:18:29.184 {'->'} 169.8 10:18:29.277 {'->'} 170.72 10:18:29.375 {'->'} 173.62 10:18:29.458 {'->'} 177.41 10:18:29.596 {'->'} -178.71 10:18:29.680 {'->'} -172.09 10:18:29.797 {'->'} -170.26 10:18:29.899 {'->'} -171.57 10:18:29.981 {'->'} -170.6 10:18:30.078 {'->'} -176.27
plot(T.(1),T.(3)) % plot third column vs first column

Sign in to comment.

More Answers (0)

Categories

Find more on Desktop in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!