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 件のコメント

Geoff Hayes
Geoff Hayes 2019 年 6 月 6 日
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
Emre Akinci 2019 年 6 月 6 日
I mean that audiofile is a signal and there are also audiofile1 and audiofile2 So i want to mix them random. So I want to do by push button
mix1 = 3*audiofile1 + 5*audiofile2 + 7*audiofile;
% coefficent is not important
Geoff Hayes
Geoff Hayes 2019 年 6 月 6 日
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
Emre Akinci 2019 年 6 月 6 日
thanks sir, it works
files are chosed from listbox1 and yes they all have same sample rate (100000x1) as it have to be
I have one more question
how can i define second or third item of listbox as a variable?
audio2 = get(handles.listbox1,'String',2);
file2 = get(handles.listbox1, 'Value',2);
these codes are right?
Walter Roberson
Walter Roberson 2019 年 6 月 6 日
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
Emre Akinci 2019 年 6 月 7 日
I can do it in popupmenu? Because I need something like that
Walter Roberson
Walter Roberson 2019 年 6 月 7 日
編集済み: Jan 2019 年 6 月 7 日
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
Emre Akinci 2019 年 6 月 7 日
Thank you sir, I will try it
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 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeScope Variables and Generate Names についてさらに検索

製品

リリース

R2017a

質問済み:

2019 年 6 月 6 日

コメント済み:

Jan
2019 年 6 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by