- () 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 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Stephen23
2017-8-8
编辑:Stephen23
2018-4-13
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 个评论
Stephen23
2017-8-8
编辑:Stephen23
2017-8-8
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!