appending characters to matrix
1 view (last 30 days)
Show older comments
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".
>>
0 Comments
Accepted Answer
Fangjun Jiang
on 24 Oct 2011
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.
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!