matlab uicontrol using figure
15 ビュー (過去 30 日間)
古いコメントを表示
So I have this code written, works completely but I just want to know are there's anyway to implement it so it's shorter, like using a set function or using a for loop?
val1 = ('csdrkjvnscklenkvt');
val2 = 2;
val3 = 3;
val4 = 4;
val5 = 5;
val6 = 6;
val7 = 7;
val8 = 8;
val9 = 9;
val10 = 10;
a = uicontrol('Style','pushbutton','Style','edit','String',val1);
pos = a.Position;
a.Position = [10 400 150 15];
b = uicontrol('Style','pushbutton','Style','edit','String',val2);
pos = b.Position;
b.Position = [10 370 50 15];
c = uicontrol('Style','pushbutton','Style','edit','String',val3);
pos = c.Position;
c.Position = [10 340 50 15];
d = uicontrol('Style','pushbutton','Style','edit','String',val4);
pos = d.Position;
d.Position = [10 310 50 15];
e = uicontrol('Style','pushbutton','Style','edit','String',val5);
pos = e.Position;
e.Position = [10 280 50 15];
f = uicontrol('Style','pushbutton','Style','edit','String',val6);
pos = f.Position;
f.Position = [10 250 50 15];
g = uicontrol('Style','pushbutton','Style','edit','String',val7);
pos = g.Position;
g.Position = [10 220 50 15];
h = uicontrol('Style','pushbutton','Style','edit','String',val8);
pos = h.Position;
h.Position = [10 190 50 15];
i = uicontrol('Style','pushbutton','Style','edit','String',val9);
pos = i.Position;
i.Position = [10 160 50 15];
j = uicontrol('Style','pushbutton','Style','edit','String',val10);
pos = j.Position;
j.Position = [10 130 50 15];
q = uicontrol('Style','pushbutton','Style','text','String','Quit');
set(q,'FontSize',15);
pos = q.Position;
q.Position = [500 20 50 20];
q.Enable = 'Inactive';
q.ButtonDownFcn = 'close(figure(1))';
0 件のコメント
採用された回答
Walter Roberson
2017 年 3 月 20 日
vals = {'csdrkjvnscklenkvt' 2 3 4 5 6 7 8 9 10 'Quit'};
nvals = length(vals);
buts = gobjects(1, nvals);
for K = 1 : nvals
buts(K) = uicontrol('Style', 'pushbutton', 'Style', 'edit', 'String', vals{K}, 'Position', [10, 430-30*K, 150, 15]);
end
2 件のコメント
Walter Roberson
2017 年 3 月 20 日
gobjects creates placeholders to hold graphics objects.
Note: it is not possible to have a single uicontrol which is two different Style -- if it is pushbutton then it cannot be edit, for example.
その他の回答 (1 件)
ES
2017 年 3 月 20 日
You can have a for loop around an uicontrol
Values = {'csdrkjvnscklenkvt', '1', '2', '3'...and so on till 9};
PositionArray = [400:-30:130]
for iloop=1:length(Values)
pushbuttopn(iloop) = uicontrol('Style','pushbutton','Style','edit','String',val1);
pushbutton(iloop).Position = [10, PositionArray(iloop), 50,15];
end
q = uicontrol('Style','pushbutton','Style','text','String','Quit');
set(q,'FontSize',15);
pos = q.Position;
q.Position = [500 20 50 20];
q.Enable = 'Inactive';
q.ButtonDownFcn = 'close(figure(1))';
2 件のコメント
伟民 苑
2022 年 6 月 12 日
編集済み: 伟民 苑
2022 年 6 月 12 日
Values = {'csdrkjvnscklenkvt', '1', '2', '3','4','5','6','7','8','9','10'};
PositionArray = (length(Values).*30+70):-30:70;
for i=1:length(Values)
pushbutton(i) = uicontrol('Style','pushbutton','Style','edit','String',Values{i});
pushbutton(i).Position = [10, PositionArray(i), 50,15];
end
q = uicontrol('Style','pushbutton','Style','text','String','Quit');
set(q,'FontSize',15);
pos = q.Position;
q.Position = [80 PositionArray(6) 50 20];
q.Enable = 'Inactive';
q.ButtonDownFcn = 'close(figure(1))';
参考
カテゴリ
Help Center および File 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!