some questions about how to read and write txt file on matlab
1 次查看(过去 30 天)
显示 更早的评论
I have create an txt file as below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163910/image.jpeg)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163911/image.jpeg)
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
采纳的回答
dpb
2014-6-7
编辑:dpb
2014-6-8
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.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!