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!