clear all
clc
format long %So that I can get more decimal places (or else it rounds)
fid = fopen('MiND_EPOC_Recording_1_txt.txt'); %opens file MiND_EPOC_Recording_1_txt.txt; must be in the same directory as this matlab file
C = textscan(fid, '%f %f %f %f %f %f %f %f %f %f %f %f %f %f'); %Saves the data in the cell array C, need a %f for EACH COLUMN

%for i = 1:length(C)
    %C{i}(C{i}==-9999.00)=NaN; %replaces every -9999.00 in each column w/ not a number
%end

fclose(fid); %closes the file
Tester = [];

fs = 44100; %sample frequency
bits = 16;

for i = 1:length(C)
%    soundsc(C{i},fs,bits);
     maxC = max(C{i}); %max of that column
     minC = min(C{i}); %min of that column
     ScaledData{i} = 2/(maxC-minC)*C{i} + (1-2*maxC/(maxC-minC)); %scales each column value between 1 and -1
     ScaledData{i}(isnan(ScaledData{i})) = 0;
     Tester = [Tester ScaledData{i}]; %For use in 'sound' (later), create regular array
end

%sound(Tester(:,2),fs);
wavwrite(Tester(:,1),fs,bits,'Data01.wav');
wavwrite(Tester(:,2),fs,bits,'Data02.wav');
wavwrite(Tester(:,3),fs,bits,'Data03.wav');
wavwrite(Tester(:,4),fs,bits,'Data04.wav');
wavwrite(Tester(:,5),fs,bits,'Data05.wav');
wavwrite(Tester(:,6),fs,bits,'Data06.wav');
wavwrite(Tester(:,7),fs,bits,'Data07.wav');
wavwrite(Tester(:,8),fs,bits,'Data08.wav');
wavwrite(Tester(:,9),fs,bits,'Data09.wav');
wavwrite(Tester(:,10),fs,bits,'Data10.wav');
wavwrite(Tester(:,11),fs,bits,'Data11.wav');
wavwrite(Tester(:,12),fs,bits,'Data12.wav');
wavwrite(Tester(:,13),fs,bits,'Data13.wav');
wavwrite(Tester(:,14),fs,bits,'Data14.wav');