Hello, I'm a novice at matlab and working on a college project. what im trying to do is have some sort of user interface, like the pic shown, that lets you select any or all of the buttons. this will represent a 5x5 matrix with either a 1 or a -1 (pressed, not pressed) then load it into the script for further calculations. is this possible/relatively simple?

1 件のコメント

Adam
Adam 2017 年 10 月 12 日
doc guide
will let you lay them out yourself
doc uicontrol
with 'style', 'togglebutton' would create an individual object so you can place them in a grid mathematically using the 'Position' property.

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

回答 (1 件)

Jan
Jan 2017 年 10 月 12 日
編集済み: Jan 2017 年 10 月 12 日

1 投票

It is "relative" simple - depending on how you define "simple".
Use either GUIDE or programmatically. Both methods have advantages. While in GUIDE you can create the buttons manually on the screen and drag them around like you want, you can use two loops to create this by code:
FigH = figure;
pos = [0, 0, 0.1, 0.1]; % [X, Y, Width, Height]
ButtonH = gobject(5, 5); % Pre-allocate
for i1 = 1:5
pos(1) = 0.05 + (i1 - 1) * 0.15;
for i2 = 1:5
pos(2) = 0.05 + (i1 - 1) * 0.15;
ButtonH(i1,i2) = uicontrol('Style', 'ToggleButton', ...
'Units', 'Normalized', 'Position', pos);
end
end
Now adjust the sizes and distances as you want.
[EDITED, Thanks Adam, ToogelButtons might be more useful for your case]

4 件のコメント

Adam
Adam 2017 年 10 月 12 日
編集済み: Adam 2017 年 10 月 12 日
I would recommend using togglebutton rather than pushbutton though if you want 'pressed' or 'not pressed' state.
Personally I almost never use toggle buttons because I use checkboxes for the same behaviour, but if you specifically want buttons that is what they are for.
Jan
Jan 2017 年 10 月 12 日
[MOVED from section for answers]
david smart wrote:
thanks for the help, i really appreciate it.
ive been playing with guide, a new feature to me. Ive gotten the buttons laid out and set them so that when they are selected they produce a 1 for the corresponding matrix coordinates, i think.
so i guess what im trying to do is have a 5x5 matrix default to all -1s and whichever toggle is selected go to 1 and then press the go button and run a script that uses hebb-net script ive written to identify which of the parameters the matrix fits. still working on it, but any help would be great.
Jan
Jan 2017 年 10 月 12 日
編集済み: Jan 2017 年 10 月 15 日
@David: Please post comments in the section for comments, because it is confusing to have them as a new answer. Thanks.
It is hard to help you noew, because the descriptions are vague only. Start with deciding either for GUIDE or for a programmatic approach. Then proceed as far as you can and then come back to the foum and ask the next specific question.
david smart
david smart 2017 年 10 月 12 日
will do, thanks and sorry. im new here

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2017 年 10 月 12 日

編集済み:

Jan
2017 年 10 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by