0

I was wondering if we can determine the number of edit text boxes in MATLAB GUIDE during the run-time?

A typical scenario would be that the user will enter a number of inputs and according to this number, I want to generate a number of edit text boxes.

the_wicked
  • 85
  • 8

2 Answers2

0

I've never used GUIDE but you can create uicontrols programatically like so:

f = figure;
nEdit = 10;

for i = 1:nEdit
   textEl(i) = uicontrol('Parent', f, 'Style', 'edit', 'Position', [0 (i-1)*30, 100, 20])
end
slayton
  • 20,123
  • 10
  • 60
  • 89
0

There are 3 parts in your question.

To answer your question title "dynamically creating edit text box in matlab guide" I would advise to use Slayton's solution and create a new figure with your n edit text boxes prompting. If you really want it in your initial guide figure, the other solution would be to initially disable them/make them invisible. Then in the callback function of your input import function you can decide how many edit text boxes you want to enable.

To answer your question

I was wondering if we can determine the number of edit text boxes in matlab guide during the run-time?

During the run-time, you can count all the text boxes in the "handles" structure this way:

hCell=struct2cell(handles);
a=0;
for i=1:length(hCell)
    if strcmp(get(hCell{i},'Type'),'uicontrol')
        if strcmp(get(hCell{i},'Style'),'edit')
            a=a+1;
        end
    end
end
a%number of edit boxes

You should ask one "if" more if in your "handles" structure you have a non-handle...

Concerning the last part of your message, I don't understand:

I won't to generate a number of edit text boxes.

hyamanieu
  • 1,055
  • 9
  • 25
  • You can also use 'findall' function rather than the double if construct now I'm facing a similar problem... – hyamanieu Nov 09 '12 at 12:29