Skip to content

Commit dcab2f1

Browse files
check for 2D matrix (#394)
1 parent 3471769 commit dcab2f1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

inst/grp2idx.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,19 @@
102102
endif
103103
is_string = true;
104104
s = cellstr (s);
105-
elseif (! (isnumeric (s) || islogical (s) || iscellstr (s)))
105+
elseif (isnumeric (s))
106+
if (! isvector (s))
107+
error ("grp2idx: 'numeric' grouping variable must be a vector.");
108+
endif
109+
elseif (islogical (s))
110+
if (! isvector (s))
111+
error ("grp2idx: 'logical' grouping variable must be a vector.");
112+
endif
113+
elseif (iscellstr (s))
114+
if (! isvector (s))
115+
error ("grp2idx: 'cell array' grouping variable must be a vector.");
116+
endif
117+
else
106118
error ("grp2idx: unsupported type for input S.");
107119
endif
108120

@@ -419,3 +431,6 @@
419431
%!error <grp2idx: 'string' grouping variable must be a vector.> ...
420432
%! grp2idx (string ({'a', 'a'; 'b', 'c'}))
421433
%!error <grp2idx: unsupported type for input S.> grp2idx ({1})
434+
%!error <grp2idx: 'numeric' grouping variable must be a vector.> grp2idx ([10, 20; 10, 30])
435+
%!error <grp2idx: 'logical' grouping variable must be a vector.> grp2idx ([true, false; false, true])
436+
%!error <grp2idx: 'cell array' grouping variable must be a vector.> grp2idx ({'a', 'b'; 'c', 'd'})

0 commit comments

Comments
 (0)