How to import non-comma/tab separated ASCII numerical data and render into vector (in matlab) -


I want to import 100,000 points of PI in matlab and want to manipulate it as a vector. I have copied these points and pasted them and saved them in a text file. I am having trouble now to import these points and provide them as a vector.

I have got the function which calculates the digits within the matlab, however, I also have difficulty in changing the output in a vector, which I could then, for example, Conspiracy (plus it is slower for at least 100,000 points on my computer.)

textscan for:

  fid = fopen ('100000.txt', 'r'); PIT = TextScan (feeds, '% c', IF); Fclose (fid);   

PiT is a cell array, so convert it to a vector of characters:

  PiT = cell2mat (PiT ( 1));   

Now, you want a vector of int, but you have to relinquish the decimal period to use standard work:

  Pi = cell2mat ( textscan (pit ([1,3: end]), '% 1d', ing);   

Note: If you manually delete this period, you can do it at once:

  fid = fopen (' 100000.txt ',' R '); Pi = cell2mat (textscan (fid, '% 1d', inf)); Fclose (fid);   

edit

Here's another solution, using fscanf , as textscan There may be no cell-type results returned. Read the file with

fscanf :

  fid = fopen ('100000.txt', 'r'); Pi = fscanf (feeds, '% c'); Fclose (fid); Then take only the digits and convert the string to a number:  
  Pi = int32 (Pi ((Pi> = '0') ) & Amp; (Pie & lt; = '9')) - int32 ('0');   

The function int32 can be replaced with other conversion functions (like double ).

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -