MATLAB read txt text file generic program

Source: Internet
Author: User

My data type is this:

0.000000 0.000000 0.000000 144 144 144 [1 0] d-1 0.000000 0.000000 0.000000 145 145 145 [2 0] d-1 0.000000 0.000000 0.00
0000 [3 0] d-1 0.000000 0.000000 0.000000 [4 0] d-1 0.000000 0.000000 0.000000 [5 0] D-1 0.000000 0.000000 0.000000 [6 0] d-1 0.000000 0.000000 0.000000 [7 0] d-1 0.000000 0.000000 0.00000 
0 141 141 141 [8 0] d-1 0.000000 0.000000 0.000000 142 142 142 [9 0] d-1 0.000000 0.000000 0.000000 [0] D-1 0.000000 0.000000 0.000000 [0] d-1 0.000000 0.000000 0.000000 [0] d-1 0.000000 0.000000 0.00000 0 193 193 193 [513] d-1 -2.042475-4.825477 32.254028 196 196 196 [514] d66-2.047885-4.900263 32.753906 199 1 199 [515] d65-2.052787-4.975761 33.258545 [516] d64 0.000000 0.000000 0.000000 39 39 39 [1249 5 D-1 0.000000 0.000000 0.000000 [1250 545] d-1 0.000000 0.000000 0.000000 [1251 545] d-1 1. #INF00 1 . #INF00 1. #INF00 50 50[1252 545] D0 1. #INF00 1. #INF00 1. #INF00 [1253 545] D0 1. #INF00 1. #INF00 1. #INF00 [1254 545] D0 1.# INF00 1. #INF00 1. #INF00 [1255 545] D0 1. #INF00 1. #INF00 1. #INF00 [1256 545] D0 0.000000 0.000000 0.000 [1257 545] d-1 0.000000 0.000000 0.000000 bayi Bayi Bayi [1258 545] d-1 0.000000 0.000000 0.000000 78 78 78 [125 9 545] D-1 0.000000 0.000000 0.000000 The [1260 545] d-1 0.000000 0.000000 0.000000 [1261 545] d-1 0.00000
 0 0.000000 0.000000 [1262 545] D-1




The length of this data is about 1000000, so I want to read the numbers. The procedure is as follows:

Clear all
close all
dispartydata = ' 1.txt ';
a1 = 1280*1024;
tmpfile= ' Tmp2.mat ';
Fidin = fopen (Dispartydata, ' R '); % open the original data file (. list)
Fidtmp=fopen (tmpfile, ' w ');% create save data file (without description text) while
~feof (Fidin)% to determine if the end of the file is
  tline= Fgetl (Fidin); % reads a line of text from the file (without the return key)
  if ~isempty (tline)% determines if the line is empty
    [M,n]=size (tline);
    flag=1;
    For i=1:n% to determine if there are no corresponding characters in the row
      (Tline (i) = = ' # ')
        flag=0;
        break;
      End
    End
    If flag==1% if it is a numeric line, write this line of data to the file
      fprintf (fidtmp, '%s\n ', tline);
    End
  End
End

fclose (Fidin);
Fclose (fidtmp);
[A,b,c,d,e,t,h,i,j] = Textread (tmpfile, '%f%f%f%d%d%d [%d] d%d ', A1);
A = [A,b,c,d,e,t,h,i,j];
Delete (tmpfile);




















Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.