- () 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!
Matlab GUI doesn't recognize cell array in the handles structure
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Aaron Smith
el 8 de Ag. de 2017
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
0 comentarios
Respuesta aceptada
Stephen23
el 8 de Ag. de 2017
Editada: Stephen23
el 13 de Abr. de 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:
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 comentarios
Stephen23
el 8 de Ag. de 2017
Editada: Stephen23
el 8 de Ag. de 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.
Ditto for this question: https://www.mathworks.com/matlabcentral/answers/351413-saving-a-logical-mask
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!