Periodically Updated Static Text and Reading from Key-Value File
조회 수: 1 (최근 30일)
이전 댓글 표시
I have two questions concerning a GUI application I'm writing:
- Is it possible to code a static text label so it periodically updates itself (from a database, or whatever) without interfering with the execution of the main application? The label would be used to cycle through news, updates, etc. That sort of thing.
- Currently, my application sets user-supplied variables by running a script, generate_appvars. I'll be compiling soon, but want to preserve this method of reading in run params at runtime. I was thinking a key-value params file which I can read into a dynamically named struct, but am unsure of how to handle vector and cell assignments (k/v pairs key = [1, 3, 5] or key = {'this', 'that'} for instance). Thinking of using eval for the right hand assignment, but don't think it's the best solution. How do other people handle runtime parameters like this?
Thanks!
댓글 수: 0
채택된 답변
Fangjun Jiang
2011년 9월 22일
For 1, you can probably use a timer object and set up the callback to refresh your text label.
For 2, you can use the parameter file to specify your key-value pairs:
par1, 1
par2, 2
par3, 3
After reading in the files, try to organize the data as:
Keys={'par1','par2','par3'}; Values={1,2,3};
Then run
a=cell2struct(Values,Keys,2)
You will get a.par1, a.par2, a.par3 holding the correct value and you've avoided the notorious evil eval.
댓글 수: 0
추가 답변 (2개)
Walter Roberson
2011년 9월 22일
1. No -- background activity always interferes with the execution of the main application.
Perhaps for your purposes it would be acceptable to code a timer whose callback fetched the data and set() the text control to the new content.
2. regexp() can help with the parsing -- though matching apostrophes can be a pain if your strings are allowed to include apostrophes.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!