Last active
November 18, 2015 19:39
-
-
Save ravnoor/78ab1df980794c6ffe9f to your computer and use it in GitHub Desktop.
Read NLES demographic data in Matlab
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
fid = fopen('DemographicNGrouping_for_NLES_Data_CT.csv'); | |
C = textscan(fid, '%s%d%s%s%s%s%d%d%d%d%d%s%d%d%d','Delimiter',',','CollectOutput', 1); | |
% reading laterality as a string instead of binary integers. | |
ID = C{1}; | |
Age = int32(C{2}); | |
Sex = C{3}(:,1); Sex(strcmp(Sex, '1')) = {'F'}; Sex(strcmp(Sex, '0')) = {'M'}; | |
Left = C{3}(:, 2); Right = C{3}(:, 3); Bilateral = C{3}(:, 4); | |
group = Left; | |
group(strcmp(group, '1')) = {'LTLE'}; group(strcmp(group, '0')) = {'RTLE'}; | |
% encode binary numbers '0' and '1' in Laterality as RTLE and LTLE. | |
Pre_Central = C{4}(:, 1); | |
Frontal = C{4}(:, 2); | |
Fronto_Central = C{4}(:, 3); | |
Post_Central = C{4}(:, 4); | |
Centro_Parietal = C{4}(:, 5); | |
Path = C{5}; | |
Duration = double(C{6}(:, 1)); | |
ISI_duration = double(C{6}(:, 2)); | |
operation=double(C{6}(:, 3)); | |
fclose(fid); | |
% write relevant fields to a structure - NLES | |
nles = []; | |
nles.id = ID; | |
nles.age = int32(Age); | |
nles.sex = Sex; | |
nles.group = Group; | |
% write relevant fields to a structure - controls | |
ctls = []; | |
ctls.id = id; | |
ctls.age = int32(age); | |
ctls.sex = sex; | |
ctls.group = group; | |
% vertically concatenate the 2 groups, nles and ctls | |
myfields = fieldnames(nles); | |
clinical = []; | |
size(myfields) | |
length(myfields) | |
for i=1:length(myfields) | |
clinical.(myfields{i}) = [ctls.(myfields{i}); nles.(myfields{i})]; | |
end | |
% write the structure as a comma delimited file. | |
struct2csv(clinical, 'clinical.csv') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment