Home > demos > demo_all_csv.m

demo_all_csv

PURPOSE ^

% README

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% README
 This is a demo script that shows how to use the draw_corr_csv function as
 well as some other related functions
 primary contact: sbf@umail.iu.edu

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% README
0002 % This is a demo script that shows how to use the draw_corr_csv function as
0003 % well as some other related functions
0004 % primary contact: sbf@umail.iu.edu
0005 
0006 
0007 %% draw_corr_csv info
0008 % [fig, data] = draw_corr_csv(csv1, column1, csv2, column2, IDs)
0009 % Required: csv1, column1, csv2, column2
0010 % Optional: IDs
0011 %
0012 % csv1 and csv2 are .csv filenames
0013 %
0014 % column1 and column2 are the two data columns to access
0015 % typical columns in csv files under multiwork/data_vis/
0016 % [subject data age]
0017 % [1 2 3] are the corresponding column numbers
0018 %
0019 % IDs can be a list of subjects or a list of experiments
0020 % if IDs is not specified, it gets all available subjects
0021 %
0022 % fig is the output figure
0023 % data is the output matrix
0024 
0025 %% Supporting Functions
0026 
0027 
0028 %% list_files
0029 % this function lists csv files in multiwork/data_vis/correlation/ that match substring input
0030 % not required to use the draw_corr_csv function, but a nice utility to get
0031 % csv file names
0032 list_files(); % will list all csv files in directory
0033 % OR
0034 list_files('cstream inhand child age prop') % will list all files with those substrings
0035 
0036 
0037 %% get_csv_data
0038 % this function gets data from a csv file
0039 
0040 % The only requirement is a valid csv file name
0041 data = get_csv_data('cevent_inhand-eye_child-child_freq_vs_age_all.csv');
0042 
0043 % Optionally, you can specify a subject list or experiment list
0044 data = get_csv_data('cevent_inhand-eye_child-child_freq_vs_age_all.csv', [], [43 32]);
0045 
0046 % Lastly, you can also specify which columns of data you want
0047 data = get_csv_data('cevent_inhand-eye_child-child_freq_vs_age_all.csv', 2, [43 44]);
0048 
0049 % data is a structure with these fields:
0050 % sub_list
0051 % data
0052 % log - logical array indicating which input subjects were actually in the
0053 % csv file
0054 % headers - returns top row of csv file
0055 
0056 %% group_csv_data #1
0057 % this function gets data from csv, but grouped together based on input
0058 % group mapping
0059 
0060 csv = 'cstream_inhand_right-hand_obj-all_parent_prop_vs_age_all.csv';
0061 grouping = [1 2 2 3]; % this means the data for 4301 will be in group1, 4302 and 4303 will be in group2, and 4304 in group3
0062 IDs = [4301 4302 4303 4304];
0063 cdata = group_csv_data(csv, grouping, IDs);
0064 
0065 %% group_csv_data #2
0066 csv = 'cstream_inhand_right-hand_obj-all_parent_prop_vs_age_all.csv';
0067 grouping = '/ein/multiwork/data_vis/grouping_example.csv'; % this is a csv with a list of some subjects in exp 43 in column 1 and the grouping categories in column 2
0068 IDs = 43; % this is a list of all subjects in 43 -- the script will just take the overlap between these subjects and the subjects indicated in the grouping column1
0069 cdata = group_csv_data(csv, grouping, IDs);
0070 
0071 %% draw_csv_group
0072 % this function will draw a correlation plot but will group data into bins
0073 % according to grouping input
0074 
0075 csv_base = 'cevent_eye_joint-attend_both_freq_vs_age_all.csv';
0076 csv_group = '/ein/multiwork/data_vis/mcdi_example.csv';
0077 draw_csv_group(csv_base, csv_group);
0078 
0079 %% draw_correlation_plots with target object
0080 
0081 clear;
0082 yvar = 'cstream_eye_roi_child';
0083 ymeasure = 'individual_prop';
0084 yargs.cevent_name = 'cevent_speech_naming_local-id';
0085 yargs.cevent_values = 1:3;
0086 yargs.sub_list = cIDs(43);
0087 yargs.label_matrix = [
0088     1 2 2 3;
0089     2 1 2 3;
0090     2 2 1 3;]; % on-targets will become 1 and off-targets will become 2, face looks become 3
0091 yargs.directory = '.';
0092 targ = {'on', 'off', 'face'};
0093 for y = 1:3
0094     yargs.filename = sprintf('testing_%s', targ{y});
0095     yargs.categories = y;
0096     draw_correlation_plots(yvar, 'individual_prop', yargs);
0097 end
0098 for y = 1:3
0099     imshow('testing_%s_prop_vs_age.png', targ{y});
0100 end
0101 
0102 
0103 %% Main Function
0104 
0105 
0106 %% basic draw_corr_csv
0107 csv1 = 'cevent_inhand-eye_child-parent_mean_dur_vs_age.csv';
0108 csv2 = 'cont_vision_size_obj#_parent_mean_vs_age.csv';
0109 col1 = 2;
0110 col2 = 2;
0111 [fig,data] = draw_corr_csv(csv1, col1, csv2, col2);
0112 
0113 %% basic with subject list
0114 
0115 csv1 = 'cevent_inhand-eye_child-parent_mean_dur_vs_age.csv';
0116 csv2 = 'cont_vision_size_obj#_parent_mean_vs_age.csv';
0117 col1 = 2;
0118 col2 = 2;
0119 subs = [4303 4305 3401 3402];
0120 [fig,data] = draw_corr_csv(csv1, col1, csv2, col2, subs);
0121 
0122 %% many-to-many or many-to-one pairing
0123 csv1 = {
0124     'cevent_inhand-eye_child-parent_mean_dur_vs_age.csv';
0125     'cstream_inhand_right-hand_obj-all_child_prop_vs_age.csv'
0126     'cstream_inhand_right-hand_obj-all_parent_freq_vs_age.csv'
0127     'cstream_inhand_right-hand_obj-all_parent_mean_dur_vs_age.csv'
0128     'cstream_inhand_right-hand_obj-all_parent_prop_vs_age.csv'};
0129 col1 = {2 2 2 2 2}; % one column is specified per element in csv1
0130 csv2 = {'cevent_eye_joint-attend_both_prop_vs_age.csv'};
0131 col2 = {[2 3]}; % pair multiple columns in a set of brackets
0132 
0133 % in this example, the column 2 data in each csv file specified in "csv1"
0134 % will be correlated with column 2 and then column 3 data in the variable
0135 % specified
0136 
0137 for c1 = 1:numel(csv1)
0138     for c2 = 1:numel(csv2)
0139         tmp1 = col1{c1};
0140         tmp2 = col2{c2};
0141         for t1 = 1:numel(tmp1)
0142       for t2 = 1 : numel(tmp2)
0143             [fig,data] = draw_corr_csv(csv1{c1}, tmp1(t1), csv2{c2}, tmp2(t2));
0144             set(fig, 'name', 'tmp')
0145             pause;
0146             if ~isempty(findobj('type', 'figure', 'name', 'tmp'))
0147                 close(fig) %will close each figure after view, comment to keep each open
0148             end
0149       end;
0150         end
0151         
0152     end
0153 end
0154 
0155 %% csv not in /ein/multiwork/correlation directory
0156 csv1 = {
0157     '/ein/multiwork/data_vis/spatial_naming.csv'};
0158 col1 = {[2 3 4 5 6 7]}; % one column is specified per element in csv1
0159 csv2 = {'cevent_speech_naming_local-id_prop_vs_age.csv'};
0160 col2 = {[2 3]}; % pair multiple columns in a set of brackets
0161 
0162 %using the same csv file, column 2 will be correlated with both column 3
0163 %and column 4, so two figures will appear
0164 
0165 for c1 = 1:numel(csv1)
0166     for c2 = 1:numel(csv2)
0167         tmp1 = col1{c1};
0168         tmp2 = col2{c2};
0169         for t1 = 1:numel(tmp1)
0170             for t2 = 1:numel(tmp2)
0171                 [fig,data] = draw_corr_csv(csv1{c1}, tmp1(t1), csv2{c2}, tmp2(t2));
0172                 set(fig, 'name', 'tmp')
0173                 pause;
0174                 if ~isempty(findobj('type', 'figure', 'name', 'tmp'))
0175                     close(fig) %will close each figure after view, comment to keep each open
0176                 end
0177             end
0178         end
0179         
0180     end
0181 end
0182

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005