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

1 次查看(过去 30 天)
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?

回答(1 个)

Walter Roberson
Walter Roberson 2013-12-13
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".

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by