@@ -83,23 +83,21 @@ function read(obj, input_struct)
8383 ~islogical(input_struct .net_atlas) && ...
8484 ~islogical(obj .matrix)
8585
86- dims = size(obj .matrix);
86+ matrix_dimensions = size(obj .matrix);
8787
88- desired_dims = obj .substituteDims(obj .dimensions, input_struct .net_atlas.numROIs,...
88+ desired_dimensions = obj .substituteDims(obj .dimensions, input_struct .net_atlas.numROIs,...
8989 nla .helpers.triNum(input_struct .net_atlas.numROIs - 1 ), input_struct .perm_count);
90- if numel(dims ) == numel(desired_dims ) && all(dims == desired_dims )
91- if obj .dimensions(1 ) == nla .inputField.DimensionType.NROIPAIRS
92- obj.matrix_ordered = nla .TriMatrix(input_struct .net_atlas.numROIs);
93- obj.matrix_ordered.v = obj .matrix;
94- else
95- obj.matrix_ordered = nla .TriMatrix(input_struct .net_atlas.numROIs);
96- obj.matrix_ordered.v = obj .matrix;
97- end
90+
91+ valid_dimensions = obj .validateDimensions(obj .dimensions, matrix_dimensions , input_struct .net_atlas.numROIs,...
92+ nla .helpers.triNum(input_struct .net_atlas.numROIs - 1 ), input_struct .perm_count);
93+ if numel(matrix_dimensions ) == numel(valid_dimensions ) && all(valid_dimensions )
94+ obj.matrix_ordered = nla .TriMatrix(input_struct .net_atlas.numROIs);
95+ obj.matrix_ordered.v = obj .matrix;
9896
9997 input_struct.(obj .name) = obj .matrix_ordered;
10098 else
10199 error = sprintf(' Matrix does not match network atlas/permutation dimensions (should be %s , is %s )!' ,...
102- join(string(desired_dims ), " x" ), join(string(dims ), " x" ));
100+ join(string(desired_dimensions ), " x" ), join(string(matrix_dimensions ), " x" ));
103101 end
104102 else
105103 error = ' Something has gone badly wrong with inputField.EdgeLevelMatrix, please report this on the NLA Github or contact an author' ;
@@ -174,6 +172,27 @@ function update(obj)
174172 end
175173 end
176174 end
175+
176+ function valid = validateDimensions(obj , input_dimensions , matrix_dimensions , number_of_rois , roi_pairs , permutations )
177+ import nla .inputField .DimensionType
178+
179+ for index = 1 : numel(input_dimensions )
180+ dimension = input_dimensions(index );
181+ if dimension == DimensionType .NROIS
182+ valid(index ) = (matrix_dimensions(index ) == number_of_rois );
183+ elseif dimension == DimensionType .NROIPAIRS
184+ valid(index ) = (matrix_dimensions(index ) == roi_pairs );
185+ elseif dimension == DimensionType .NPERMS
186+ valid(index ) = (matrix_dimensions(index ) >= permutations );
187+ else
188+ if isstring(number_of_rois )
189+ valid(index ) = (matrix_dimensions(index ) == string(dimension ));
190+ else
191+ valid(index ) = (matrix_dimensions(index ) == dimension );
192+ end
193+ end
194+ end
195+ end
177196
178197 function str = dimsAsString(obj )
179198 str = join(obj .substituteDims(obj .dimensions, " nrois" , " nroipairs" , " nperms" ), " x " );
0 commit comments