MATLAB Answers

How to Compare multiple rows of the Same txt file at the same time.

24 views (last 30 days)
AIDAN DEITCH
AIDAN DEITCH on 18 Feb 2021
Edited: dpb on 18 Feb 2021
I have a txt file that contains a time column and a distance column. I am trying to write a script that will find the greatest absolute differnce between any 2 consectuive distance values and return that value. I am having trouble figuring out how to accsess two rows of a list at the same time. Any help is greatly appriceated and I have posted my code below.
  2 Comments
AIDAN DEITCH
AIDAN DEITCH on 18 Feb 2021
Okay sorry for incorrect formatting this is my first time posting here. Thank you for the reply.

Sign in to comment.

Answers (1)

dpb
dpb on 18 Feb 2021
Edited: dpb on 18 Feb 2021
Read the file(s) into memory with importdata or other high-level function appropriate to the format; then use diff() on the second column (presuming time is first) and max() with optional location parameter to return the position. Remember the length will be one less than original array length.
<Import Text-files> is link to documentation on bringing in text files in MATLAB. It's much simpler than you're making it! :)

Tags

Community Treasure Hunt

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

Start Hunting!