why it will go wrong using 'cell'?

1 vue (au cours des 30 derniers jours)
warnerchang le 31 Mar 2022
Commenté : warnerchang le 1 Avr 2022
Recently, I ran two codes as follow:
% it will go wrong
  2 commentaires
warnerchang le 31 Mar 2022
however,what happened behind cell function? As far as I know, a = {[],[]} and b = cell(1,2) should get the same result.

Connectez-vous pour commenter.

Réponse acceptée

Jan le 31 Mar 2022
Modifié(e) : Jan le 31 Mar 2022
I confirm, that this is an inconsistent behavior.
a = {[], []};
b = cell(1, 2);
isequal(a, b)
ans = logical
a{1}([]) = [] % Working: Nothing is deleted as expected
a = 1×2 cell array
{0×0 double} {0×0 double}
b{1}([]) = [] % Failing:
Deletion requires an existing variable.
Both methods create a cell array of the same size, but cell() fills the elements with a NULL pointers, while {[], []} creates empty matrices. Matlab should treat NULL pointers as empty matrices, but as you see in this example, this exception has been forgotten sometimes. You cannot detect the NULL points from inside Matlab, but on the C level this is easy. KSSV's method to check the used memory is a strong hint also.
Report this bug to MathWorks. The function for deleting will be updated than to catch this exception.
  1 commentaire
warnerchang le 1 Avr 2022
thank you for reply!

Connectez-vous pour commenter.

Plus de réponses (0)


En savoir plus sur Function Creation dans Help Center et File Exchange





Community Treasure Hunt

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

Start Hunting!

Translated by