Reading text file, matlab

后端 未结 2 1072
刺人心
刺人心 2021-01-25 12:47

I am reading a text file \'mytext.text\' in matlab. Data file looks like:

1   -4436.6910  415.1843    -3019.7497  1,3,4,5,21,23

2   -4366.4541  1353.9975   -308         


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-01-25 13:26

    To read a single line do

    % Read at most 4 elements
    data1234 = fscanf (fid, '%d %f %f %f', 4);
    % Read as many elements as possible, stop when no ',' is found
    data5 = fscanf (fid, '%d,');
    

    Continue reading lines until you reached the end of the file (save the data from each line before doing that). So you need some loop that continues doing this untill the file ends.

提交回复
热议问题