Created
February 27, 2014 00:11
-
-
Save diego898/e2ca8d4807f7a004719f to your computer and use it in GitHub Desktop.
parseBrainAmpFile will read and parse the specified file which was exported from the brainamp
This file contains hidden or 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
function output = parseBrainAmpFile(filename) | |
%parseBrainAmpFile Read in and parse a BrainAmp File | |
% | |
% parseBrainAmpFile(filename) will read in the specified file | |
% which was exported from the brainamp | |
% | |
% output is struct containing two members: | |
% names - a matrix where each row is the name of the data row | |
% values - a [#names * #samples] matrix containing the data | |
%% Calculate Number of Samples | |
% Reads in first line | |
fid = fopen(filename); | |
line = fgetl(fid); | |
fclose(fid); | |
firstLine = textscan(line, '%s', 'CollectOutput', true); | |
numSamples = size(firstLine{1},1) - 1; | |
%% Parse File | |
fid = fopen(filename); | |
format = ['%s ' repmat('%f', [1 numSamples]) '%*[^\n\r]']; | |
fileData = textscan(fid, format, 'CollectOutput', true); | |
fclose(fid); | |
%% Format Output | |
output.names = cell2mat(fileData{1}); | |
output.values = fileData{2}; | |
end % end function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment