I want to define the following as a string in matlab, from s to ).
set(handles.edit,'string','some string')

6 件のコメント

Stephen23
Stephen23 2023 年 7 月 4 日
"I want to define the following as a string in matlab, from s to )."
What is the intended application of this?
chrisw23
chrisw23 2023 年 7 月 4 日
i.e. (just use double quotes)
handles.edit.string = "some string"
rmpirooz
rmpirooz 2023 年 7 月 4 日
No. I didn't mean this. I want something like following. But Matlab generates error message.
str = 'set(handles.edit,'string','some string')'
rmpirooz
rmpirooz 2023 年 7 月 4 日
I have lots of set and get commands which I need to generate them within a for loop do that I have not to type all of them.
Stephen23
Stephen23 2023 年 7 月 4 日
Rik
Rik 2023 年 7 月 4 日
Why don't you explain what you actually want to do? You have described enough for us to know that what you are asking us is a terrible idea, but we don't know what your end goal is.

サインインしてコメントする。

 採用された回答

Stephen23
Stephen23 2023 年 7 月 4 日
編集済み: Stephen23 2023 年 7 月 4 日

0 投票

"I have lots of set and get commands which I need to generate them within a for loop do that I have not to type all of them."
Do NOT do that.
Firstly, (assuming MATLAB graphics object context) both SET and GET accept multiple handles and/or properties. It is often NOT required to call them multiple times, each time to just SET/GET one property. Read the SET/GET documentation to know more:
Secondly, if for whatever reason you decide to call SET/GET with one handle/property each time, then do NOT create strings of the whole command. That would be a terrible way to write code. Instead you simply put the handles and properties in some arrays and loop over them, e.g.:
P = ["String","Position","Color"];
C = {'Hello world!',[0,0.2,0.5,0.7],'r'};
for k = 1:numel(S)
set(handles.edit,P(k),C{k})
end
But the best solution is to provide SET/GET with multiple inputs, if that is possible.
Do NOT generate text of the commands you want to run. Ugh.

3 件のコメント

rmpirooz
rmpirooz 2023 年 7 月 7 日
The code you provided if I have just one edit box.
I have 160 edit boxes (for some reasons I cannot use tables in my GUI) and depending on some conditions some the edit boxes must becom visible and some else invisible.
I want to generate the codes within the for loop so that I have not to generate 160 lines of commands for every conditon.
The problem is that the tag of the edit boxes cannot be generated in a for loop.
chrisw23
chrisw23 2023 年 7 月 7 日
CtrlName = ["edit1" "edit2" "edit3"] % ...160
P = ["String","Position","Color"];
C = {'Hello world!',[0,0.2,0.5,0.7],'r'};
for k = 1:numel(S)
set(handles.(CtrlName(k)),P(k),C{k})
end
Rik
Rik 2023 年 7 月 7 日
For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.
Apart from that, you can generate CtrlName with sprintf so you don't have to write them all.
But using an array to store the handles is probably a better solution once you move away from GUIDE.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDesktop についてさらに検索

製品

リリース

R2012b

タグ

質問済み:

2023 年 7 月 4 日

コメント済み:

Rik
2023 年 7 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by