% read all data from file
fid = fopen('survey.csv');
str = fread(fid)';
fclose(fid);
len = length(str);

% figure out where the quotes are
quotes = find(str=='"');
inquotes = zeros(1,len);
for ii = 1:length(quotes)/2
  inquotes(quotes(ii*2-1):quotes(ii*2))=1;
end

% figure out the delimiters
delimiters = find(str==','|str==10);

% chop data up into entries using delimiters, making sure those in quotes
% are not used.
data = cell(1,length(delimiters));
prevloc = 0;
kk = 0;
for ii = 1:length(delimiters)
  if ~inquotes(delimiters(ii))
    kk = kk + 1;
    data{kk} = char(str(prevloc+1:delimiters(ii)-1));
    prevloc = delimiters(ii);
  end
end
data(kk+1:end)=[];

data{end+1}='';

data = reshape(data,[239 785]);
header = data(:,1)';
data = data(:,2:end)';


options = cell(1,38);
indices = cell(1,38);
for ii = 8:length(header)
  hh = header{ii};
  ss = regexp(hh,'Question(?<number>\d+)(?<field>.*)','names');
  jj = str2num(ss.number);
  options{jj}{end+1} = ss.field;
  indices{jj}(end+1) = ii;
end

question{1}='Do you conduct research in, teach, or study machine learning?';
type{1}='yesno';
question{2}='What do you do?';
type{2}='choice';
question{3}='Which department(s) are you based in?';
type{3}='multiplechoice';
question{4}='Which conferences do you regularly attend?';
type{4}='multiplechoice';
question{5}='Do you have (or have you had) students in machine learning?';
type{5}='yesno';
question{6}='What is your educational background/training/disciplinary background?';
type{6}='multiplechoice';
question{7}='Did your educational background prepare you well for research in machine learning?';
type{7}='1=ill-prepared,4=well-prepared';
question{8}='What educational backgrounds do your students have?';
type{8}='multiplechoice';
question{9}='Did the educational backgrounds of your students prepare them well for studying machine learning?';
type{9}='1=ill-prepared,4=well-prepared';
question{10}='In your opinion, what will constitute good educational backgrounds for a graduate student entering machine learning?';
type{10}='multiplechoice';
question{11}='What area(s) in machine learning do you work in?';
type{11}='multiplechoice';
question{12}='What other area(s) do you work in?';
type{12}='multiplechoice';
question{13}='In your opinion, what are core (foundation) areas of machine learning?';
type{13}='multiplechoice';
question{14}='In your opinion, machine learning is a subfield of statistics.';
type{14}='1=disagree,4=agree';
question{15}='In your opinion, machine learning is a subfield of computer science.';
type{15}='1=disagree,4=agree';
question{16}='In your opinion, machine learning is a subfield of cognitive science.';
type{16}='1=disagree,4=agree';
question{17}='In your opinion, machine learning is a subfield of neuroscience.';
type{17}='1=disagree,4=agree';
question{18}='In your opinion, machine learning is a subfield of engineering.';
type{18}='1=disagree,4=agree';
question{19}='In your opinion, machine learning is a subfield of artificial intelligence.';
type{19}='1=disagree,4=agree';
question{20}='In your opinion, machine learning is an interdisciplinary area.';
type{20}='1=disagree,4=agree';
question{21}='In your opinion, machine learning is a a discipline distinct from other disciplines.';
type{21}='1=disagree,4=agree';
question{22}='Any further comments regarding the relationship of machine learning to other disciplines?';
type{22}='freetext';
question{23}='In your opinion, in the university, machine learning should ideally be a group within computer science.';
type{23}='1=disagree,4=agree';
question{24}='In your opinion, in the university, machine learning should ideally be a group within neuroscience.';
type{24}='1=disagree,4=agree';
question{25}='In your opinion, in the university, machine learning should ideally be a group within engineering.';
type{25}='1=disagree,4=agree';
question{26}='In your opinion, in the university, machine learning should ideally be a group within statistics.';
type{26}='1=disagree,4=agree';
question{27}='In your opinion, in the university, machine learning should ideally be a group within psychology.';
type{27}='1=disagree,4=agree';
question{28}='In your opinion, in the university, machine learning should ideally be a spread across multiple departments.';
type{28}='1=disagree,4=agree';
question{29}='In your opinion, in the university, machine learning should ideally be an interdisciplinary centre.';
type{29}='1=disagree,4=agree';
question{30}='In your opinion, in the university, machine learning should ideally be its own department.';
type{30}='1=disagree,4=agree';
question{31}='In your opinion, in the university, machine learning should be taught at the graduate level.';
type{31}='1=disagree,4=agree';
question{32}='In your opinion, in the university, machine learning should be taught as a specialist track in a related undergraduate programme.';
type{32}='1=disagree,4=agree';
question{33}='In your opinion, in the university, machine learning should be taught in a dedicated undergraduate programme.';
type{33}='1=disagree,4=agree';
question{34}='In your opinion, in which departments should machine learning be taught?';
type{34}='multiplechoice';
question{35}='Any further comments regarding the place of machine learning within the university?';
type{35}='freetext';
question{36}='What brought you into machine learning?';
type{36}='multiplechoice';
question{37}='In your opinion, what are the goals of machine learning?';
type{37}='multiplechoice';
question{38}='Do you have further comments regarding any part of this survey?';
type{38}='freetext';

