Remove all doubles, cell arrays and char arrays from a structure?
5 次查看(过去 30 天)
显示 更早的评论
I am writing a piece of software with a GUIDE interface.
My data is all stored in the handles structure. In hindsight, I should have put every variable the user enters, and every result of calculations in a seperate structure like UserData.XXX rather than handles.XXX but it's a very large interface and I am working to a tight time constraint so can't easily change this now.
When the user opens a new GUI, I clear all of the edit boxes and result outputs whose tag names end in INPUT or OUTPUT. It's fast and works well, but the data remains in the handles structure. When a computation button is pressed again, naturally it still works, as the data is still present even if the GUI is empty.
How can I remove fields from the handles structure if (and only if) they are character arrays, doubles, or cell arrays? That way my GUI UIControl data, panels etc. can remain in the handles structure.
I was hoping to easily use the class and rmfield functions, but I can only get the class function to identify that handles is a struct, rather than return the class of each item contained within it.
Thanks, Matt.
2 个评论
Stephen23
2018-10-26
"In hindsight, I should have put every variable the user enters, and every result of calculations in a seperate structure like UserData.XXX rather than handles.XXX but it's a very large interface and I am working to a tight time constraint so can't easily change this now."
That might be your best option. I would simply replace your handles.XXX with handles.mystuff.XXX, which could be done with a simple text find-and-replace, although you have to check each one so that you do not change the GUIDE fields, which will take a few minutes. After that, you can process/replace/initialize/... the contents of handles.mystuff as you require.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!