%% Read File Contents into Column Vector
% Create a sample text file that contains floating-point numbers.

x = 100*rand(8,1);
fileID = fopen('nums1.txt','w');
fprintf(fileID,'%4.4f\n',x);
fclose(fileID);

%
% View the contents of the file.

type nums1.txt

%
% Open the file for reading, and obtain the file identifier, fileID.

fileID = fopen('nums1.txt','r');

%
% Define the format of the data to read. Use '%f' to specify floating-point numbers.

formatSpec = '%f';

%
% Read the file data, filling output array, A, in column order. fscanf reapplies the format, formatSpec, throughout the file.

A = fscanf(fileID,formatSpec)

% A is a column vector containing data from the file.
%
% Close the file.

fclose(fileID);

% Copyright 2012 The MathWorks, Inc.