some questions about how to read and write txt file on matlab

1 view (last 30 days)
I have create an txt file as below:
then I can read it into matlab by csvread/dlmread, which is ok.but when I change the file as below, it will be never read again:
1. So how shall I read the txt file as above into matlab normally?
2. how shall I add or delete some date, such as numbers 1,2,4 or charactors a,b,c and so on into the txt file?
3. image that an txt file was written by an procedure about 1 time 1 data per 0.1 seconds and the txt file would be written done (completed), then I will read this file at once to get the last data by matlab and do some computing for it. question: how shall I know the file is done or not by matlab?
thank you

Accepted Answer

dpb
dpb on 7 Jun 2014
Edited: dpb on 8 Jun 2014
1) When you switch to mixed character/numeric data, then csvread and friends are no longer suitable to use--they can't (and are documented to not) handle anything except regular all-numeric input. If you must make such changes, you'll need to use textscan that will return a cell array and you'll also have difficulty if the format of which field within the array changes form in reading the file as anything but fully text as the formatting will need to match. Looks like a very overhead-intensive way to try to do things.
2) See above; keep the whole thing as character or make a different storage structure of separate lists to handle the two if must have both types.
3) That's a tough one because of file buffering and all in the OS that you don't have direct control of. What's the other process; can it read input from standard input so you could dispatch with SYSTEM? Or, look at memmapfile and into using a flag variable.

More Answers (0)

Categories

Find more on Software Development Tools in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!