How can i define variables in gui?
Afficher commentaires plus anciens
Hey everyone I want to define variables like:
function pushbutton15_Callback(hObject, eventdata, handles)
audio = get(handles.listbox1,'String');
file = get(handles.listbox1, 'Value');
audiofile = audioread(audio{file});
and I want to use "audiofile" in math operators.
what I need to do?
9 commentaires
Geoff Hayes
le 6 Juin 2019
Emre - please clarify what you mean I want to use audiofile in math operators. Which math operators? Do you want to use these audio samples outside of this callback? Or do you mean something else?
Emre Akinci
le 6 Juin 2019
Geoff Hayes
le 6 Juin 2019
How is audiofile1 and audiofile2 "loaded"? Via the same pushbutton15_Callback or through a different one? Will it be guaranteed that each audio file has the same number of samples so that the above addition will work successfully? If so, then you may want to save the samples to a matrix where each column (or row) represents one of those audio files.
As for making the audio data available to the other callbacks, you can "save" the samples to the handles structure so that other callbacks access that data. For example,
function pushbutton15_Callback(hObject, eventdata, handles)
audio = get(handles.listbox1,'String');
file = get(handles.listbox1, 'Value');
[Y,Fs] = audioread(audio{file});
handles.Y = Y;
handles.Fs = Fs;
guidata(hObject, handles); % <--- saves the updated struct
Then, other callbacks would check to see if handles.Y exists to try and use that data.
Emre Akinci
le 6 Juin 2019
Walter Roberson
le 6 Juin 2019
You cannot define entries of a listbox as variables. Listboxes have one Value property, and one String property. Value is typically a scalar positive integer, but in some cases can be a (possibly empty) vector of positive integers. String is typically a cell array of character vectors, but in some cases can be a char array.
All you can do is retrieve the Value property and retrieve the String property and use the Value to index the String property.
Emre Akinci
le 7 Juin 2019
Walter Roberson
le 7 Juin 2019
Modifié(e) : Jan
le 7 Juin 2019
You cannot define entries of a popup as variables. popups have one Value property, and one String property. Value is a scalar positive integer. String is typically a cell array of character vectors, but in some cases can be a char array.
All you can do is retrieve the Value property and retrieve the String property and use the Value to index the String property.
Emre Akinci
le 7 Juin 2019
Emre Akinci
le 7 Juin 2019
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Scope Variables and Generate Names dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!