Динамично добавьте поля к MATLAB GUI?

Используйте Infinity и -Infinity, когда реализация математического алгоритма призывает к нему.

В Ruby, Infinity и -Infinity имеют хорошие сравнительные свойства так, чтобы -Infinity < x < Infinity для любого вещественного числа x. Например, Math.log(0) возвраты -Infinity, расширяясь на [1 111] свойство, что x > y подразумевает это Math.log(x) > Math.log(y). Кроме того, Infinity * x Infinity если x> 0, -Infinity если x < 0, и 'NaN' (не число; то есть, неопределенный), если x 0.

, Например, я использую следующий бит кода в части вычисления [приблизительно 1 124] логарифмические отношения правдоподобия . Я явно ссылочный -Infinity для определения значения, даже если k 0 или n И x, 0 или 1.

Infinity = 1.0/0.0
def Similarity.log_l(k, n, x)
  unless x == 0 or x == 1
    k * Math.log(x.to_f) + (n-k) * Math.log(1.0-x)
  end
    -Infinity
  end
end

5
задан gnovice 7 July 2009 в 18:28
поделиться

2 ответа

One way to accomplish this is to create the GUI objects at the start, but set their "Visibility" property to "off". Then, when the user clicks on a button, you set the "Visibility" property back to "on". This way, you won't be making new GUI objects while the GUI is running, you would simply be changing which parts of it are visible or not.

EDIT: If you don't know how many new GUI objects you need until run-time, this is how you would add the new GUI objects to the handles structure (where hFigure is a handle to the GUI figure):

p = uicontrol(hFigure,'Style','pushbutton','String','test',...
              'Callback',@p_Callback);  % Including callback, if needed
handles.test = p;  % Add p to the "test" field of the handles structure
guidata(hFigure,handles);  % Add the new handles structure to the figure

You would then of course have to write the callback function for the new GUI object (if it needs one), which might look something like this:

function p_Callback(hObject,eventdata)
  handles = guidata(gcbf);  % This gets the handles structure from the figure
  ...
  (make whatever computations/changes to GUI are needed)
  ...
  guidata(gcbf,handles);  % This is needed if the handles structure is modified

Functions of interest that I used in the above code are: GUIDATA (for storing/retrieving data for a GUI) and GCBF (get handle of parent figure of the object whose callback is currently executing).

6
ответ дан 14 December 2019 в 01:14
поделиться

Using UICONTROL, you will be able to add 'fields' (called uicontrols or widgets).

You will want to specify the style to get edit boxes, buttons, etc...

You may actually want to have all the widgets already there in GUIDE and then just change the visibility or enabled property as needed.

You can find my video tutorials on GUI building in MATLAB here: http://blogs.mathworks.com/videos/category/gui-or-guide/

This should cover this and many related topics in GUI building.

3
ответ дан 14 December 2019 в 01:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: