How do i make a uipanel with checkboxes return information to my script?
Show older comments
Bottom line im trying to get my uifigure checkboxes to create a logical vector(f) that consistis of zeroes or ones based on what checkboxes gets selected.
All the files needed to run the code is attached, the BoxChanged.m function changes the value of the checkbox depending on wheter or not the respective box is selected(i think)
further than that i cant seem to get tho, considering i dont know how to use this to display information.
this function creates vectors simulating a 6 dice dicethrow
function [result] = terning(d,ant)
%TERNING Playing a random number of same sided dice
% Creating a result vector for the played dice. Taking the inputs d and
% ant to determine what results we get when we play ant d-sided dice.
result = randi(d,1,ant);
end
here is the function creating checkboxes:
function [box] = hukboks(a,b,y,p)
%This funcion creates a Checkbox in uifigure p, where b is a placeholder
%for hom many boxes needs to be made, and a is a counter telling the
%function how many boxes has been made, y is a variable setting names for
%the boxes
%S is the size of the checkbox(big enough for 1 digit)
%v is the spacing in pixels for left to right of the figure
%h is the distance(in pixels) from the bottom of the figure to the row of
%checkboxes
v = 700.*(a/b);
h = 350;
s = 25;
n = num2str(y);
box = uicheckbox(p,'text',n,'Position',[v h s s],...
'ValueChangedFcn',@(box,event) BoxChanged(box));
end
this function checks the value of the checkboxes(if the changed or not)
function BoxChanged(bx)
%Determining what will happen when Checkboxes are selected
val = bx.Value;
if val
bx.Value = 1;
else
bx.Value = 0;
end
end
this is the script i made to try to create my output vector f
p = uifigure('Name','PLZ HELP','Position',[150 100 909 539]);
kastvektor = terning(6,6);
b = length(kastvektor);
f = zeros(1,b);
for a = 1:b
y = kastvektor(a);
if a == 1
box1 = hukboks(a,b,y,p);
end
if a == 2
box2 = hukboks(a,b,y,p);
end
if a == 3
box3 = hukboks(a,b,y,p);
end
if a == 4
box4 = hukboks(a,b,y,p);
end
if a == 5
box5 = hukboks(a,b,y,p);
end
if a == 6
box6 = hukboks(a,b,y,p);
end
end
As explained earlier im trying to convert the zeroes vector f to become a vector of ones and zeroes corresponding to inputs from my panel.
Attached is also how the panel may look with boxes 1 to 6 going from left to right
Please if you know anything or have tips let me know im kinda smashing my heasd against a wall here.
Accepted Answer
More Answers (0)
Categories
Find more on Develop Apps Programmatically in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!