|
46 | 46 |
|
47 | 47 | end |
48 | 48 |
|
49 | | - if isfield(cfg, 'testingDevice') && strcmpi(cfg.testingDevice, 'scanner') |
| 49 | + if isfield(cfg, 'testingDevice') && strcmpi(cfg.testingDevice, 'mri') |
50 | 50 | fieldsToSet.MRI.repetitionTime = []; |
51 | 51 | end |
52 | 52 |
|
53 | | - %% set the defaults |
54 | | - % loop through the defaults and set them in cfg if they don't exist |
| 53 | + cfg = setDefaults(cfg, fieldsToSet); |
| 54 | + |
| 55 | + % sort fields alphabetically |
| 56 | + cfg = orderfields(cfg); |
| 57 | + |
| 58 | +end |
| 59 | + |
| 60 | +function structure = setDefaults(structure, fieldsToSet) |
| 61 | + % loop through the defaults fiels to set and update if they don't exist |
| 62 | + |
55 | 63 | names = fieldnames(fieldsToSet); |
56 | 64 |
|
57 | 65 | for i = 1:numel(names) |
58 | | - cfg = setFieldToIfNotPresent( ... |
59 | | - cfg, ... |
| 66 | + |
| 67 | + thisField = fieldsToSet.(names{i}); |
| 68 | + structure = setFieldToIfNotPresent( ... |
| 69 | + structure, ... |
60 | 70 | names{i}, ... |
61 | | - getfield(fieldsToSet, names{i})); %#ok<GFLD> |
62 | | - end |
| 71 | + thisField); |
63 | 72 |
|
64 | | - %% sort fields alphabetically |
65 | | - cfg = orderfields(cfg); |
| 73 | + end |
66 | 74 |
|
67 | 75 | end |
68 | 76 |
|
69 | | -function struct = setFieldToIfNotPresent(struct, fieldName, value) |
70 | | - if ~isfield(struct, fieldName) |
71 | | - struct = setfield(struct, fieldName, value); %#ok<SFLD> |
| 77 | +function structure = setFieldToIfNotPresent(structure, fieldName, value) |
| 78 | + if ~isfield(structure, fieldName) |
| 79 | + structure.(fieldName) = value; |
72 | 80 | end |
73 | 81 | end |
0 commit comments