Skip to content

Instantly share code, notes, and snippets.

@whacked
Created September 17, 2010 06:21
Show Gist options
  • Save whacked/583811 to your computer and use it in GitHub Desktop.
Save whacked/583811 to your computer and use it in GitHub Desktop.
example of reading yaml into a matlab struct via java interop
%% read YAML and put into matlab struct
%% http://code.google.com/p/snakeyaml/
import('org.yaml.snakeyaml.Yaml');
yamlreader = Yaml();
yml = fileread(yml_filepath);
jymlobj = yamlreader.load(yml);
num_question = jymlobj.size;
vec_Q = {};
for i = 1:num_question
jls_qobj = jymlobj.get(java.lang.Integer(i));
for j = 0:jls_qobj.size-1 % java array index is 0 to size-1
jqobj = jls_qobj.get(j);
vec_Q{i, j+1, 1} = jqobj.get('question');
q_right = jqobj.get('correct');
if length(q_right) > 0
vec_Q{i, j+1, 2} = q_right;
vec_Q{i, j+1, 3} = jqobj.get('incorrect');
%% ... etc ...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment