How to save number of arrays as different instances in a file?

1 view (last 30 days)
I have saved two arrays in a file but as a single instance. I wish to save them seperately so that I can read them separately as well. This is my code
function A= write(M)
fid=fopen('output.txt','a+');
for i = 1:size(M,1)
fprintf(fid,'%g\t',M(i,:));
fprintf(fid,'\n');
end
fclose(fid);
I have two arrays as follows.
a =
10 20 30
20 78 89
c =
1 3
4 7
6 89
10 98
I have stored them already in file. How to make them as separate instances so that when i read I can read the array I want and not just the entire file?

Answers (1)

Walter Roberson
Walter Roberson on 13 Dec 2013
In text files, there is no way to avoid reading leading information -- in your example, no way to avoid reading the text corresponding to "a" if you are interested in "c".
Binary files, on the other hand, can be "jumped around in".

Categories

Find more on Cell Arrays 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!