Passing value of variable instead of string
Show older comments
Hello,
I have a GUI made with guide and I encounter a problem. A function is computing some data and then should display it on a uitable. However, I have multiple UItable (named datatable_1 to datatable_5) and when I use get and set, I have a Invalid handle object. Here is the code :
tablename = ['handles.datatable_',num2str(row)]; <-- row corresponds to the uitable I want to update
cellFN = get(tablename, 'data');
I'd like the functions get and set to understand tablename as handles.datatable_ n and not as tablename. I've been looking around the FAQs and forum but found nothing (apart from the demonic eval). If anyone as an idea that would be great.
Thank you,
Vincent
PS: already tried to use cell or structure to force the good interpretation but in vain.
3 Comments
If you had put the handles into an array then this would be trivial with indexing. By deciding to make lots of separate variables you have painted yourself into a corner, because now your bad design decision limits your to writing bad, slow, complex, buggy code.
This is why we are always telling beginners not to create numbered variables and or try to access them. Indexing is simple, neat, and very efficient, and works with graphics handles perfectly. Indexing does not require cell arrays or structures for your situation: for R2014b or later create the array using gobjects, while for pre-2014b MATLAB versions use zeros or nan.
Your bad data design requires accessing the variable names, which will always be slow, complex, and buggy:
Vincent MAILLET
on 24 Oct 2017
Edited: Vincent MAILLET
on 24 Oct 2017
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Identification 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!