Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
5011_Big_Data/textscanDemo.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
33 lines (25 sloc)
1004 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Filename and Format string | |
% This code loads in the contents of the data file with textscan a block at a | |
% time and converts the cellarray from textscan into a double array | |
% Copyright 2011 The MathWorks, Inc. | |
filename='waferdata_start.csv'; | |
FormatString=['%*f%*f%*f%*f' repmat('%f',1,9) repmat('%*f',1,7)]; | |
%% Parameters | |
Headers = 3 ; | |
NumLines = 1e6 ;% Total number of lines to read | |
BlockLines = 10000 ;% Size of block | |
NumBlocks = NumLines/BlockLines; % Number of blocks | |
%% Open file | |
fid = fopen(filename); % Open file | |
%% Preallocate data | |
data=zeros(NumLines,9); % Pre-allocate space for data | |
%% Get Headers | |
cellchunk=textscan(fid,'%s',3,'delimiter','\n'); % Get first 3 lines | |
%% Read in blocks | |
for Block=1:NumBlocks | |
data((Block-1)*BlockLines+(1:BlockLines),:) = ... | |
cell2mat(textscan(fid,FormatString,BlockLines,'delimiter',',')); | |
disp(['Block ' num2str(Block) ]); % Display current block to show progress | |
end | |
%% Close file | |
fclose(fid); |