Buttons to a matrix
이전 댓글 표시
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
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개)
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
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
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.
@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
2017년 10월 12일
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!