Is it possible to create a "0-by-0" matrix (or array)?
matlab
Solution
`[]` is the matlab notation for an empty 0-by-0 matrix. You created a 0-by-0 matrix, it's simply displayed in another way.
>> size(reshape([], [0 0]))
ans =
0 0
Problem
`reshape` can create both a `0-by-1` matrix and a `1-by-0` matrix: ``` >> reshape([], [0 1]) ans = Empty matrix: 0-by-1 >> reshape([], [1 0]) ans = Empty matrix: 1-by-0 ``` `reshape` can also create an n-dimensional array, for n > 2, in which at least one of the dimensions is 0. For example1 ``` >> reshape([], [6 0 1 2 1]) ans = Empty array: 6-by-0-by-1-by-2 ``` But I have not managed to coax `reshape` into producing a `0-by-0` anything (matrix or array, that is). For example ``` >> reshape([], [0 0]) ans = [] >> reshape([], [0 0 1]) ans = [] ``` Is there any way to generate an entity that MATLAB will display interactively as a `0-by-0` matrix? Better yet, is there a way to create an entity that MATLAB will display interactively as an m-by-n array, for any non-negative integers m and n?2 (My interest in this question comes from wanting to make the value returned by a function I'm writing a bit more consistent, i.e. less surprising to the user, across the range of valid input arguments.) 1 Note how any trailing dimensions of size 1 are automatically removed, as long as they appear after the second position. 2 More precisely, I'm looking for an `x` such that (1) `isnumeric(x)` is `true`; (2) `numel(x)` is 0; and (3) typing `x` at the MATLAB prompt and hitting `[RETURN]` produces the displayed output `Empty matrix: 0-by-0` (or `Empty array: 0-by-0`).