Use textscan
for that:
fid = fopen('100000.txt','r');
PiT = textscan(fid,'%c',Inf);
fclose(fid);
PiT
is a cell array, so convert it to a vector of chars:
PiT = cell2mat(PiT(1));
Now, you want a vector of int, but you have to discard the decimal period to use the standard function:
Pi = cell2mat(textscan(PiT([1,3:end]),'%1d', Inf));
Note: if you delete (manually) the period, you can do that all in once:
fid = fopen('100000.txt','r');
Pi = cell2mat(textscan(fid,'%1d',Inf));
fclose(fid);
EDIT
Here is another solution, using fscanf
, as textscan
may not return a cell-type result.
Read the file with fscanf
:
fid = fopen('100000.txt','r');
Pi = fscanf(fid,'%c');
fclose(fid);
Then take only the digits and convert the string as digits:
Pi = int32(Pi((Pi>='0')&(Pi<='9')))-int32('0');
Function int32
may be replaced by other conversion functions (e.g. double
).