How can I read this text file?
조회 수: 2 (최근 30일)
이전 댓글 표시
I wrote this text file, then I wrote this code to read it and it gives me errors.
Error using dataread Trouble reading floating point number from file (row 1, field 2) ==> ,500,1000,1500,2200,2900,3600,4
Error in textread (line 168) [varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1>
This is what I have, [t, Q]=textread('spherical.txt','%d %f');
Can someone help?
댓글 수: 0
채택된 답변
Walter Roberson
2018년 5월 28일
... Is there a good reason to write in that particular format? There are other easier formats.
textread() was declared obsolete a fair number of years ago; you should probably not be using it for any new code (unless you are using a very old MATLAB release.)
S = fileread('spherical.txt');
parts = regexp(S, ';', 'split');
t = cell2mat(textscan(parts{1}, '%d', 'delimiter', ','));
Q = cell2mat(textscan(parts{2}, '%f', 'delimiter', ','));
Note: your t has 12 entries, but your Q only has 11 entries.
Are you sure you want your t variables to be int32 data type? It is possible, and even quite appropriate for some cases, but if you are not aware that it will be int32 then you can end up with problems in the computation. If you want double instead of int32 then use %f instead of %d. If you want 64 bit integers use %d64
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!