How can I read this text file?

2 visualizaciones (últimos 30 días)
Roberto Gomez
Roberto Gomez el 28 de Mayo de 2018
Comentada: Roberto Gomez el 29 de Mayo de 2018
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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Mayo de 2018
... 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
  1 comentario
Roberto Gomez
Roberto Gomez el 29 de Mayo de 2018
Thanks, I fixed the entries to be the same. I will look into an alternative for textread().

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by