Tab completion of struct within cell

7 vues (au cours des 30 derniers jours)
Anna le 18 Mar 2019
Commenté : Anna le 25 Mar 2019
Hello together,
I am working on a large object-oriented database where it happens that I store structs or instances of classes within a cell. However, I experience that the autocomplete or tab completion function of Matlab does not work anymore after the cell. So, for example I define a struct "structTest":
structTest.a = 2;
structTest.b = 4;
The autocompletion works fine:
Now I save this struct within the cell "cellTest":
cellTest = cell(2,1);
cellTest{1,1} = structTest;
Unfortunately, the autocompletion does not work anymore:
Similarly, the problem occurs when I save instances of classes within a cell.
After reading about .json files for tab completion of functions and overriding the properties(obj) function in the class definition with fieldnames(obj), I still don't have a clue on how to deal with this. Especially since fieldnames(cellTest{1,1}) works just fine:
>> fieldnames(cellTest{1,1})
ans =
2×1 cell array
Any suggestions on this? It would be of great advantage, as users sometimes have to navigate quite deeply into the database.
Thank you very much for your help,

Réponse acceptée

Guillaume le 18 Mar 2019
The reason why tab completion doesn't work for the content of a cell array can easily be explained: matlab does not look into the cell array to see what type of data is stored there.
Now you could argue that maybe it should but maybe it shouldn't. After all, cell arrays are used to store heterogeneous data, so most likely while it may be a structure in there now, maybe it will be a double next time. cell content tend to change type more often than variables do. And if all the cells are always a structure, why aren't you using a structure array instead? Tab completion will work without problems on a structure array.
In any case, the current version of matlab does not look inside the cell array, so there's no work around.
  3 commentaires
Anna le 19 Mar 2019
"By default, class instances are arrays, so you don't need a cell array for that (unless you've coded the class in a way that completely breaks if the instances are not scalar, or you've specifically disallowed array creation). "
I didn't know that - just tried it and it works fantastically! Thanks for the hint!

Connectez-vous pour commenter.

Plus de réponses (1)

Ken Atwell
Ken Atwell le 23 Mar 2019
If you can try the just-released R2019a, MATLAB will now tab completion in this situation.
  1 commentaire
Anna le 25 Mar 2019
Oh really? Great!! I'll propably wait until the release of 2019b, but then will definitively upgrade! Thank you very much for this information!

Connectez-vous pour commenter.


En savoir plus sur Data Types 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