Creating Checkboxes based on a while loop

1 回表示 (過去 30 日間)
yySBU
yySBU 2018 年 6 月 27 日
コメント済み: yySBU 2018 年 7 月 4 日
Hello,
I am creating a system where it populates checkboxes based on a variable's value. (Using GUIDE mainly for GUI but to do this section, I am writing my own code) This is part of the code below:
while i < numOfElem
c(i) = uicontrol(panel,'Style','checkbox', 'String', elementTitles(i).title);
c(i).Position = [10 10 920-i.*50 920-i.*50];
i = i + 1;
end
numOfElem is the number of times it loops, as well as the number of times I would like the checkboxes to populate one underneath the other (with different strings -> elementTitles(i).title).
Each title appears with a checkbox, however, my method deletes the previous checkbox because I am overwriting it.
How can I solve this issue?
Thank you

採用された回答

Adam Danz
Adam Danz 2018 年 6 月 27 日
編集済み: Adam Danz 2018 年 6 月 27 日
What units are you plotting in? Assuming 'panel' is the handle to the GUI figure,
panel.Units
It looks like you're using pixels but when you reposition the checkbox, you position if way off of the figure.
To test that, after this line in your code
c(i).Position = [10 10 920-i.*50 920-i.*50];
add this line to see if it re-appears (assumes units are pixels)
c(i).Position = [20 20 60 20]; % assumes figure size is default [403 246 560 420]
  7 件のコメント
yySBU
yySBU 2018 年 7 月 4 日
Hello,
I finally figured out my problem. Yes, it was the positioning of the checkboxes and I realized it after debugging and coloring the foreground. The whole column had turned into one solid color which was why the checkbox background had been pasted over each other.
Thank you Mr. Danz for your help.
I changed my code to look like this:
c.Position = [10 450-i*20 60 20];
I was changing the checkbox sizes instead of the placements. (Even though the background of the checkboxes were the only thing that changed. The checkbox size itself didn't change.)
yySBU
yySBU 2018 年 7 月 4 日
Picture mentioned above

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by