Docsity

Matlab GUI, Slide di Bioimaging

Anteprima parziale del testo

Scarica Matlab GUI e più Slide in PDF di Bioimaging solo su Docsity!

Strumentazione per bioimmagini

Interfacce grafiche (GUIs)

in MatLab

Cos’è un’interfaccia grafica

a = input(‘inserire il primo addendo’);b = input(‘inserire il secondo addendo’);somma = a + b;disp([‘

somma =

‘,num2str(somma)])

Interfaccia che in maniera grafica e intuitiva permette all’utente di interagirecon un programma (inserire input e ricevere output di vario tipo)

DEI - Univ. Padova (Italia)

VS

Design del layout

Blank GUI

DEI - Univ. Padova (Italia)

Design del layout – creazione degli elementi

DEI - Univ. Padova (Italia)

Design del layout

DEI - Univ. Padova (Italia)

Programmazione degli elementi

Quando si salva la GUI, GUIDE crea automaticamente un M-file che può contenerediverse sezioni: Commenti

: mostrati nella command window in risposta al comando help.

Inizializzazione della GUI

: Alcune istruzioni di inizializzazione create da GUIDE.

Questo codice non deve essere modificato.

Opening function

: qui

si

possono

inserire

le

inizializzazioni

da

eseguire

prima

che

DEI - Univ. Padova (Italia)

Opening function

: qui

si

possono

inserire

le

inizializzazioni

da

eseguire

prima

che

l’utente inizi ad interagire con la GUI.

Output function

: restituisce outputs alla command line dopo l’esecuzione della

opening function

Component and figure callbacks

: funzioni che controllano il comportamento del pannello principale della GUI e dei sui varicomponenti. Permettono di gestire eventi relatividegli elementi e della GUI stessa.

Utility/helper functions

: funzioni varie non direttamente associate ad un evento.

Programmazione degli elementi

function

input1_editText_Callback(hObject, eventdata, handles)

% store the contents of input1_editText as a string. if the string% is not a number then input will be empty input = str2num(get(hObject,'String')); % checks to see if input is empty. if so, default input1_editText to zero

Esempio di programmazione di un edit_textbox

DEI - Univ. Padova (Italia)

% checks to see if input is empty. if so, default input1_editText to zero if

(isempty(input))

set(hObject,

'String'

, '0'

)

end guidata(hObject, handles);

Programmazione degli elementi

% --- Executes on button press in add_pushbutton. function

add_pushbutton_Callback(hObject, eventdata, handles)

% get data from the field “String” of the element with tag “input1_editText” a = get(handles.input1_editText,

'String'

);

% get data from the field “String” of the element with tag “input2_editText” b = get(handles.input2_editText,

'String'

);

Esempio di programmazione di un push_button

DEI - Univ. Padova (Italia)

% a and b are variables of Strings type, and need to be converted% to variables of Number type before they can be added together total = str2num(a) + str2num(b);c = num2str(total);

% need to convert the answer back into String type to display it

% set data to the field “String” of the element with tag “answer_staticText” set(handles.answer_staticText,

'String'

,c);

guidata(hObject, handles);