why it will go wrong using 'cell'?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
warnerchang
am 31 Mär. 2022
Kommentiert: warnerchang
am 1 Apr. 2022
Recently, I ran two codes as follow:
a={[],[]};a{1}(a{1}==3)=[];
% it will go wrong
b=cell(1,2);b{1}(b{1}==3)=[];
2 Kommentare
Akzeptierte Antwort
Jan
am 31 Mär. 2022
Bearbeitet: Jan
am 31 Mär. 2022
I confirm, that this is an inconsistent behavior.
a = {[], []};
b = cell(1, 2);
isequal(a, b)
a{1}([]) = [] % Working: Nothing is deleted as expected
b{1}([]) = [] % Failing:
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.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!