I've been in the same situation where I've had essencially 2D data stored in a 3D array with a singleton dimension and I'm left wondering, why doesn't MATLAB know what I want to do!? In those cirumstances my intentions seems so obvious that I wonder why the software can't read my mind.
Yesterday I was loading a draft of an upcoming Graphics and App Building blog article into WordPress by copying it from a carefully formatted Word document. Upon previewing the article, WordPress tried to be smarter than me and removed all line break tags requiring me to manually fix the end of each paragraph. Obviously this is what he wants, WordPress thought. WordPress was wrong. Fortunately I caught the error.
Should software try to interpret the user's intentions?
In some cases, yes (my opinion, of course). For example, MATLAB knows that 'r' should be interpreted as 'red' when specifying color properties in graphics objects. The uitextarea command will automatically wrap a 1xn character array based on the width of the text box, assuming the user didn't intend for the text to be cut off or extend beyond the text box (the text command, on the other hand, does not wrap).
In many other cases, particularly in areas of core math and data visualization where silent wrong answers can be dangerous, we try to catch nonsensical inputs and workflows by returning warnings or errors but we probably shouldn't be silently tweaking the user's input data. If an input has multiple dimensions, it is my opinion that we should assume that is intentional and if the function was not built for multiple dimensions, it shouldn't adapt the inputs "to make it work".
Problems with squeezing out singleton dimensions
MATLAB already implicitly reduces an infinite number of trailing singleton dimensions. For example,
size(t)
ans =
5 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Thus, plotting functions that accept matrices would accept this input since it would be trimmed prior to plotting execution.
Squeezing non-trailing singleton dimensions is where things get murky. Many plotting functions are sensitive to the shape of the inputs. For example, when M is a 2D matrix in plot(M), a line is plotted for each column of M and the number of rows of M determine the number of points per line. Here is an example where M is a 1x2x1x3 4D array and N is a 3x1x2 3D array, both of which have the same 6 values. M is squeezed to a 2x3 matrix and N is squeezed to a 3x2 matrix. The result is a different number of lines and coordinates.
Are these the intended results? -- It depeneds on the logic used to store those data.
Would the user be aware of what happened here? -- Maybe not. I've occasionally forgotten that a variable has more than two dimensions until an error message pops up.
M = reshape(vals,[1 2 1 3]);
N = reshape(vals,[3,1,2]);
Msqueezed = squeeze(M)
Msqueezed =
1 3 5
2 4 6
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Nsqueezed = squeeze(N)
Nsqueezed =
1 4
2 5
3 6
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
plot(nexttile(),Msqueezed,'-o')
plot(nexttile(),Nsqueezed,'-o')
Conclusion
For these reasons, it is my opnion that a helpful error message is the correct response. I see MATLAB users as incredibly smart and also incredibly busy people. It's important that we find ways to simplify the use of MATLAB but for topics like this where simplifcation can lead to problems, it's better to rely on human brains.