Import Data From Text File and Analyse
Mostra commenti meno recenti
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?
Risposta accettata
Più risposte (2)
KSSV
il 30 Mar 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 Commenti
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
il 30 Mar 2017
Uditha Samarakoon
il 30 Mar 2017
Modificato: Uditha Samarakoon
il 30 Mar 2017
Uditha Samarakoon
il 30 Mar 2017
0 voti
Categorie
Scopri di più su Large Files and Big Data in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!