Remove all doubles, cell arrays and char arrays from a structure?
4 views (last 30 days)
Show older comments
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 Comments
Stephen23
on 26 Oct 2018
"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.
Answers (0)
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!