yamlmatlab
yamlmatlab copied to clipboard
cellarray of struct donesn't correctly check fields to precede in makematrices of ReadYaml
I have a yaml file like this:
condtestpath: ConditionTest_V1_358_conditiontest_1.yaml condtest: CONDSTATE:
- - PREICI: 20.2806
- COND: 128.3246
- SUFICI: 632.8663
- - PREICI: 733.4108
- COND: 833.4752
- SUFICI: 1333.7605
- - PREICI: 1451.4685
- COND: 1566.3031
- SUFICI: 2083.5186
- - PREICI: 2198.9955
- COND: 2300.4615
- SUFICI: 2801.3268
- - PREICI: 2916.3761
- COND: 3032.1373
- SUFICI: 3532.1772
- - PREICI: 3644.487
- COND: 3746.5744
- SUFICI: 4249.5801
- - PREICI: 4366.9403
- COND: 4480.8218
- SUFICI: 4982.1106
- - PREICI: 5099.0864
- COND: 5214.5976
- SUFICI: 5716.7272
after readyamlraw, in makematrices in function result = iscompatible(obj1, obj2) import yaml.*; result = isequal(class(obj1), class(obj2)); end
it's always return true because it doesn't check if obj1 and obj2 have the same number of fields and if those fields have the same names, so it will precede to try to make a matrices out of the cell array of struct which may not have the same number of fields/names
the quickest way to avoid such thing is to add fields checking, I could make a small PR if you like.
Yes that would be nice. Can you also write a unittest?
i looked at my hack again, and not sure if it deserve a unittest.
Basically, i just replace a line of code and make it more strict as to whether to tried to build a matrix out of a array of struct, so my data wouldn't pass the check and leave it to me to further process.
function result = iscompatible(obj1, obj2)
import yaml.*;
% result = isequal(class(obj1), class(obj2));
result = isequal( fieldnames(obj1),fieldnames(obj2));
end
I am not sure this modification altered any other function behavior that the code originally means. but if you are sure the modification is valid, i could try to write a test with my data (I have to admit i seldom write unit test, bad habit, i know :).
Also, i run the selftest_yamlmatlab and it showed this: