MATLAB: Appending characters to matrix

appendc

I tried to append characters to a matrix:
>> matrix=[1:3;6:8]
matrix =
1 2 3
6 7 8
>> fid=fopen('mongiss.tv', 'w')
fid =
5
>> fprintf(fid, '%d %d\n', matrix)
ans =
12
>> fclose(fid)
ans =
0
>> load mongiss.tv >> mongiss
mongiss =
1 6
2 7
3 8
>> fid=fopen('mongiss.tv', 'a')
fid =
5
>> fprintf(fid, '%d %d\n', 1, 4)
ans =
4
>> fclose(fid)
ans =
0
>> fid=fopen('mongiss.tv', 'a')
fid =
5
>> fprintf(fid, '%c %c\n', 'y', 'n')
ans =
4
>> fclose(fid)
ans =
0
>> load mongiss.tv
??? Error using ==> load
Unknown text on line number 5 of ASCII file
C:\Users\Tor\Documents\MATLAB\mongiss.tv
"y".
>>

Best Answer

The file is written correctly. It is just that the function load() can't deal with it. If you read the help of load(). It says "With -ASCII, LOAD will error if the file is not numeric text.".
You can use importdata('mongiss.tv') to read the data. The data will be read in a structure though.
But to verify that you can append characters to a text file with numerical data, you've achieved the goal. You can use a text editor to verify it.