Created
September 17, 2010 06:21
-
-
Save whacked/583811 to your computer and use it in GitHub Desktop.
example of reading yaml into a matlab struct via java interop
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
%% 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