diff --git a/+bids/Model.m b/+bids/Model.m index a50619dd..c206c9c6 100644 --- a/+bids/Model.m +++ b/+bids/Model.m @@ -926,6 +926,45 @@ function write(obj, filename) end + function validate_constrasts(obj, node) + + if ~isfield(node, 'Contrasts') + return + end + + for iCon = 1:numel(node.Contrasts) + + if ~isfield(node.Contrasts{iCon}, 'Weights') + msg = sprintf('No weights specified for Contrast %s of Node %s', ... + node.Contrasts{iCon}.Name, node.Name); + bids.internal.error_handling(mfilename(), ... + 'weightsRequired', ... + msg, ... + obj.tolerant, ... + obj.verbose); + end + + switch node.Contrasts{iCon}.Test + case 't' + nb_weights = numel(node.Contrasts{iCon}.Weights); + case 'F' + nb_weights = size(node.Contrasts{iCon}.Weights, 2); + end + + if nb_weights ~= numel(node.Contrasts{iCon}.ConditionList) + msg = sprintf('Number of Weights and Conditions unequal for Contrast %s of Node %s', ... + node.Contrasts{iCon}.Name, node.Name); + bids.internal.error_handling(mfilename(), ... + 'numelWeightsConditionMismatch', ... + msg, ... + obj.tolerant, ... + obj.verbose); + end + + end + + end + end methods (Static) @@ -996,39 +1035,6 @@ function write(obj, filename) end end - % could be made static - function validate_constrasts(node) - - if ~isfield(node, 'Contrasts') - return - end - - for iCon = 1:numel(node.Contrasts) - - if ~isfield(node.Contrasts{iCon}, 'Weights') - msg = sprintf('No weights specified for Contrast %s of Node %s', ... - node.Contrasts{iCon}.Name, node.Name); - bids.internal.error_handling(mfilename(), ... - 'weightsRequired', ... - msg, ... - obj.tolerant, ... - obj.verbose); - end - - if numel(node.Contrasts{iCon}.Weights) ~= numel(node.Contrasts{iCon}.ConditionList) - msg = sprintf('Number of Weights and Conditions unequal for Contrast %s of Node %s', ... - node.Contrasts{iCon}.Name, node.Name); - bids.internal.error_handling(mfilename(), ... - 'numelWeightsConditionMismatch', ... - msg, ... - obj.tolerant, ... - obj.verbose); - end - - end - - end - end methods (Access = protected)