Passing value of variable instead of string

조회 수: 4 (최근 30일)
Vincent MAILLET
Vincent MAILLET 2017년 10월 24일
댓글: Vincent MAILLET 2017년 10월 25일
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
Vincent MAILLET
Vincent MAILLET 2017년 10월 24일
편집: Vincent MAILLET 2017년 10월 24일
Hi,
Thank you for your quick answer. I didn't know the existence of gobjects. And since I currently have Matlab2010 it is not available. I will try your technic as soon as I have the newest version
Stephen23
Stephen23 2017년 10월 24일
편집: Stephen23 2017년 10월 24일
" I will try your technic as soon as I have the newest version"
Why wait? Using an array works for any version: for any pre-2014b version just use an array of doubles.

댓글을 달려면 로그인하십시오.

채택된 답변

Cam Salzberger
Cam Salzberger 2017년 10월 24일
Hello Vincent,
Stephen is correct about code design, and I would recommend making arrays of handles. Prior to "gobjects" being available, feel free to pre-allocate the array with simple doubles, or just build the array dynamically. Your graphics objects array should be sufficiently small for it to not have a huge impact on code.
If you would like a stop-gap measure that will work with your numbered variables, you can use dynamic field names for structures:
handles.(['datatable_' num2str(1)])
-Cam

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by