Read text file in matlab (data trancation)

前端 未结 1 557
无人共我
无人共我 2021-01-26 05:03

I am reading a text file in matlab . Here is the code

allData = textread(file\', \'%s\', \'delimiter\', \'\\n\');

numericalArray = cellfun(@(s) ss         


        
相关标签:
1条回答
  • 2021-01-26 05:45

    There are various ways to read this sort of data (space-delimited). In all methods precision is preserved.

    Assuming you have the input in demo.txt:

    Method 1: simple textscan

    fid = fopen('demo.txt','r'); % open for reading
    txt = textscan(fid,'%s','delimiter', '\n'); txt = txt{1}; % read lines and unbox
    fclose(fid);
    
    H = strsplit(txt{1},' '); % split the headers line
    V = str2double(strsplit(txt{2},' '));
    

    Method 2: dlmread

    R = dlmread('demo.txt',' ',1,0); % this is an example in the documentation of dlmread
    

    Method 3: readtable

    T = readtable('demo.txt');
    
    0 讨论(0)
提交回复
热议问题