Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How do I efficiently edit GUIDE item handles in a loop?

조회 수: 2 (최근 30일)
Carlo Cavaliere Ballesta
Carlo Cavaliere Ballesta 2019년 2월 21일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a program written using GUIDE (yes, I still use it), and i'm trying to modify the properties a series of objects named Sector1, Sector 2... SectorN in a loop. The problem is, to do this I'm currently using eval (expression), such as:
expression = ['set(handles.Sector',num2str(i),',''Position'', pos1);'];
eval(expresion);
But it runs terribly slow, as the recommendations here state. I'm wondering if there is a workaround to avoid using eval while still being able to call the objects in a loop. Thanks.
  댓글 수: 3
Stephen23
Stephen23 2019년 2월 21일
편집: Stephen23 2019년 2월 21일
"I'm wondering if there is a workaround to avoid using eval while still being able to call the objects in a loop"
Just access them directly in handles using dynamic fieldnames:
Remember that putting numbers into variable names is a sign that you are doing something wrong... as you are finding out, it forces you into writing slow, complex, buggy code that is hard to debug. Read this to know why:
Using indexing would be the most efficient solution and is what you should have used.
Personally I would also avoid GUIDE. Ultimately it is simpler to write your own code.
Carlo Cavaliere Ballesta
Carlo Cavaliere Ballesta 2019년 2월 22일
Thank you both, i managed to avoid using eval by using dynamic fieldnames, as you suggested. Thank you again for your time.

답변 (0개)

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by