how to fread not a file, but a vector that equals fread a file in binary form?
조회 수: 4 (최근 30일)
이전 댓글 표시
I have a vector
aVec = [45,234,123,.........]
% that is equivalent to:
% fread(anyfile, 'r')
I want to read that vector as text file and get lines:
fid = fopen( filepath, 'rt')
fgetline(fid)
Is there a way that skips the file writing to hardisk and directely read the vector as file?
Maybe
java.io.StringBufferInputStream
or other ways?
댓글 수: 0
채택된 답변
Guillaume
2019년 9월 1일
There is not fread(fileid, 'r'), there is a fopen(filename, 'r') but that tells us nothing about how you read the file initially.
Assuming that you've read the file as fread(fileid), then what you've got is the sequence of bytes (inefficiently stored as double) and converting that back to characters may just be simply:
chardata = char(aVec);
if you want to split that into lines:
lines = strsplit(char(aVec), {'\n', '\r'})
The above assumes that the file text encoding is the same as that used by matlab. If not, you'll have to use native2unicode with the proper encoding first.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!