How can i define variables in gui?

8 次查看(过去 30 天)
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 个评论
Emre Akinci
Emre Akinci 2019-6-7
Can I do that I want with different buttons One button for every variable? Using uigetfile

请先登录,再进行评论。

采纳的回答

Jan
Jan 2019-6-7
It depends on what "use "audiofile" in math operators" mean. After your code, audiofile is a variable, which contains the signal of a sound. You can work with this variables as usual - inside this callback. If you want to share the contents of the variable with other callbacks:
function pushbutton15_Callback(hObject, eventdata, handles)
fileName = get(handles.listbox1,'String');
index = get(handles.listbox1, 'Value');
audioSignal = audioread(fileName{index});
handles.audioSignal = audioSignal;
guidata(hObject, handles);
end
function anyOther_Callback(hObject, eventdata, handles)
audioSignal = handles.audioSignal;
... % Do what you like with the signal here
end
I've used more meaningful names for the variables here. The list of files names is not really "audio", and the chosen index is not really "file". The contents of the file is not really "audiofile".
"Can I do that I want with different buttons One button for every variable? Using uigetfile"
Again, it depends on what you want to do. "One button for every variable" is not clear. Of course you can use uigetfile, so which problem do you have with it?
  2 个评论
Emre Akinci
Emre Akinci 2019-6-7
I'm creating a GUI about Independent Component Analysis with audio signals. So I want the user can select any file from ilstbox but I understood I can't because I had to define every listbox item as variable that looks impossible So I will uigetfile and buttons for audiofiles user can select files so i will work on it
Jan
Jan 2019-6-7
I do not understand, why you mean, that listbox items have to be variables. Perhaps this is useful:
...
function YourGUI_OpeningFcn(hObject, EventData, handles)
baseFolder = 'C:\Your\Data\Folder'; % Or uigetdir() ?
fileList = dir(fullfile(baseFolder, '*.wav'));
set(handles.popupmenu1, 'String', {fileList.name});
handles.baseFolder = baseFolder;
guidata(hObject, handles);
end
function pushbutton15_Callback(hObject, eventdata, handles)
fileName = get(handles.listbox1,'String');
index = get(handles.listbox1, 'Value');
audioSignal = audioread(fullfile(handles.baseFolder, fileName{index}));
handles.audioSignal = audioSignal;
guidata(hObject, handles);
end
This populates the popupmenu with the file names contained in the specified folder. You can access these files later on.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

产品


版本

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by