Import Data From Text File and Analyse
Mostrar comentarios más antiguos
How to import following data set from text file to matlab ? Must avoid from missing data (_) raws(entire raw). How can do it with matlab code?
Respuesta aceptada
Más respuestas (2)
KSSV
el 30 de Mzo. de 2017
fid = fopen('LRFData.txt','r') ;
S = textscan(fid,'%s','delimiter','\n') ;
fclose(fid) ;
S = S{1} ;
S = cellfun(@str2num,S,'un',0) ; % convert strings to numbers
S = S(~cellfun('isempty',S)) ; % remove the empty cells/ missing cells
S = cell2mat(S) ; % convert cell to matrix
3 comentarios
Using cellfun and str2num will be slow and inefficient, and str2num also calls eval which means this code will have dangerous and unintended side effects if the file contains non-numeric data.
See my answer for a much more efficient and robust solution, using textscan to correctly identify the missing data.
Uditha Samarakoon
el 30 de Mzo. de 2017
Uditha Samarakoon
el 30 de Mzo. de 2017
Editada: Uditha Samarakoon
el 30 de Mzo. de 2017
Uditha Samarakoon
el 30 de Mzo. de 2017
0 votos
Categorías
Más información sobre Large Files and Big Data en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!