Matlab GUI doesn't recognize cell array in the handles structure

3 vues (au cours des 30 derniers jours)
Aaron Smith
Aaron Smith le 8 Août 2017
Modifié(e) : Stephen23 le 13 Avr 2018
I have a matlab GUI with a number of apps. One of the apps creates a cell array which I have saved in the handles structure. In a later callback, I have called this cell array in an attempt to apply a logical mask to the data contained in the cells. I have been attempting to fix the persistent error: Cell contents reference from a non-cell array object.
I will attach the relevant callbacks but I stored the cell array in the handles structure as:
handles.finishCell = finishCell{k}; %k is the number of cells in finishCell
And then I called it in the second callback using a number of different variations:
Y = handles.finishCell;
Y = handles.finishCell{:};
Y = handles.finishCell{handles.k}; % I saved k as handles.k in the first callback
Y = handles.finishCell{k}; % after having stated k = handles.k;
Each of these variations generated the same error and I'm not sure what the solution could be

Réponse acceptée

Stephen23
Stephen23 le 8 Août 2017
Modifié(e) : Stephen23 le 13 Avr 2018
Instead of
handles.finishCell = finishCell{k};
you need
handles.finishCell = finishCell(k);
A cell array is a collection of containers. You could think of them as being like boxes: you can put things into (or get out of) of the boxes, or you can handle the boxes themselves. Each of these is useful in different situations. Just like there is a difference between "I'll go get my teddybear out of its box in the attic", and "I'll get that box with my teddybear in it down from the attic": in you case you end up with your teddybear in your hand, and in the other you have a box in your hand.
MATLAB gives you the same control:
  • () parentheses simply returns a part of the array that you are indexing into: numeric if a numeric array, char if a char array, cell if a cell array, table if table, etc. Therefore this gives you the box itself!
  • {} curly braces accesses the contents of a cell array or table. This gets things in/out of the box!
Your mistake was to get whatever it was out of the cells... and that is the numeric data that you had earlier allocated into that cell array (and is clearly not a cell array).
Read more here:
  2 commentaires
Aaron Smith
Aaron Smith le 8 Août 2017
Thanks Stephen. This appears to be working. Such a simple fix, I can't believe I never got it
Stephen23
Stephen23 le 8 Août 2017
Modifié(e) : Stephen23 le 8 Août 2017
If it works then please consider accepting the answer. Accepting an answer is an easy way for to to show your appreciation for the volunteers who spend their time helping you. And it shows others that your question has been resolved.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by