is there a way to give suggestions to Mathworks

7 vues (au cours des 30 derniers jours)
Philippe Lebel
Philippe Lebel le 28 Mai 2018
Réponse apportée : Jaromir le 23 Août 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 commentaires
Walter Roberson
Walter Roberson le 29 Mai 2018
If performance is the goal, then adding 1 to an all-zero matrix would typically be slower than initializing to all 1.
Initializing to all 1 can be done with a memset() type of function, which in turn could be turned into SIMD hardware instructions for efficiency that only has to write blocks without reading them.
Adding 1 to an all-zero matrix invokes generalized addition, which has to read, add, write.
dpb
dpb le 29 Mai 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.

Connectez-vous pour commenter.

Réponse acceptée

Steven Lord
Steven Lord le 28 Mai 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.

Plus de réponses (1)

Jaromir
Jaromir le 23 Août 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

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by