How can i write to a particular line in a csv file

5 次查看(过去 30 天)
Hi All
I have a file and am writing to it in blocks. The blocks can come in any order and be any size and they must go to a specific line in the csv file.
Using fprintf i have been able to write to any pre-exisitng line but have been unable to go beyond the last line i wrote. E.g. if i first write to line 10000 with a block of data 100 lines long then i can write to line 5000 without issue however any attempt to write to line 20000 results in the data being written to Without loading in the file and appending to the end of the data at 10101.
Any suggestions welcome..

回答(1 个)

Joseph Cheng
Joseph Cheng 2014-7-28
If you check what a CSV file looks like you'd understand what you need to do. As a CSV is just a text file with data that has a deliminator of a comma and each line is terminated with a new line character. To get to line 20000 after writing the 10000 block you'd need to create N new lines at the end of the file to get to line 20000.
How are writing to line 10000? is there any data before or after? how do you get to line 10000 in the first place? Can you supply representative code of what you've tried?

产品

Community Treasure Hunt

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

Start Hunting!

Translated by