is there a way to give suggestions to Mathworks

7 views (last 30 days)
Philippe Lebel
Philippe Lebel on 28 May 2018
Answered: Jaromir on 23 Aug 2018
Hi,
I stumbled upon a warning mentioning that in future versions of matlab, cell arrays and list (not sure about lists) will be required to have the correct size to be concatenated. We will not be able to concatenate an empty (0x0) cell array with a 1x3 cell array for example.
This warning tells us that we need to create it with the correct number of columns.
Currently there is no (clean) way to create empty arrays and lists. The only way i found was to create it with functions such as zeros(0,n) and ones(0,n).
But these functions are not intended for this use case.
I tried to search a place where i could suggest Matlab to implement a way to initialize empty lists, cell arrays, structures and so on, but I couldn't find this place.
Thus I'm asking the question: Is there a place where we can suggest features to implement in future versions of Matlab?
Thank you!
  12 Comments
dpb
dpb on 29 May 2018
"Yes, and an other reason is that the name of these functions implies that you want to create a matrix filled with zeroes or ones, not an empty matrix. If the name of functions was not important and only the result was important, the reason for the creation of the function ones() could have been discarded because zeroes() existed and after the creation of the array, you could have just added "1" the the matrix, filling it with ones."
"Syntactic sugar" -- there are many special-purpose functions in Matlab introduced solely for the purpose of simplifying code; just as there are an almost infinite number of ways to fill an array with a value if one doesn't care to use the obvious for some reason. If you don't like the name for a particular purpose, then build yourself a utility function of whatever name you would prefer and use it instead.

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 28 May 2018
Contacting Technical Support using the Contact Us link in the upper-right corner of this page is the way to officially file an enhancement request.
If you want to report an error or request additional information be added to a documentation page, you could press the No button next to the "Was this topic helpful?" question at the end of a documentation page instead of contacting Support.
But now about the enhancement request you want to file, you can create empty cell arrays, struct arrays, or object arrays in several different ways.
C = cell(0, 5) % builds a 0-by-5 cell array
C2 = reshape({}, 0, 5) % Another way to build a 0-by-5 cell array
S = struct('field1', C) % 0-by-5 struct array with one field named field1
S2 = repmat(struct, 0, 5) % 0-by-5 struct array with no fields
S3 = repmat(struct('field2', 5), 0, 5) % 0-by-5 struct array with
% one field named field2
For objects, use the empty method.

More Answers (1)

Jaromir
Jaromir on 23 Aug 2018
Hi Philippe
There is a very clean way to create an empty array of any class in Matlab. Each class (including your own user-defined ones, unless you override the behavior) has a static method empty for this purpose. The following example commands will create empty arrays of the respective kind (class) and size:
cell.empty(15, 0)
double.empty(0, 5, 6)
char.empty(1, 0)
Best Jaromir

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!