How can i define variables in gui?
古いコメントを表示
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
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
2019 年 6 月 6 日
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
2019 年 6 月 6 日
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
2019 年 6 月 7 日
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
2019 年 6 月 7 日
Emre Akinci
2019 年 6 月 7 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Scope Variables and Generate Names についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!