필터 지우기
필터 지우기

appending characters to matrix

조회 수: 1 (최근 30일)
Tor Fredrik Hove
Tor Fredrik Hove 2011년 10월 24일
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".
>>

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 10월 24일
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.
  댓글 수: 1
Tor Fredrik Hove
Tor Fredrik Hove 2011년 10월 24일
Thanks for the answer! I got through it by using fgetl:
>> fid=fopen('mongiss.tv')
fid =
5
>> while ~feof(fid)
oneline=fgetl(fid)
end
oneline =
1 6
oneline =
2 7
oneline =
3 8
oneline =
1 4
oneline =
y n
>>

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by