How can i define variables in gui?
Show older comments
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 Comments
Geoff Hayes
on 6 Jun 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
on 6 Jun 2019
Geoff Hayes
on 6 Jun 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
on 6 Jun 2019
Walter Roberson
on 6 Jun 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
on 7 Jun 2019
Walter Roberson
on 7 Jun 2019
Edited: Jan
on 7 Jun 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
on 7 Jun 2019
Emre Akinci
on 7 Jun 2019
Accepted Answer
More Answers (0)
Categories
Find more on Scope Variables and Generate Names in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!