フィルターのクリア

Undefined function or variable 'hObject' in app designer

9 ビュー (過去 30 日間)
Chunhui Guo
Chunhui Guo 2018 年 1 月 23 日
コメント済み: Brian 2018 年 8 月 29 日
[filename, pathname] = uigetfile('*.mp3', 'Select audiofile');
[a,fs]=audioread([pathname filename]);
handles.B1 = audioplayer(a,fs);
play(handles.B1);
guiData(hObject,handles);
I have this code and it keep telling me that the hObject is undefined. I want to use it for a push button, so that when I click the button, it will let me to select a sound file and play it. I know I need to use guidata function to save it in order to play it. However, I don't really know how to use it, like how to create an hObject in order to make it work properly.

回答 (1 件)

Melissa Williams
Melissa Williams 2018 年 1 月 24 日
編集済み: Melissa Williams 2018 年 1 月 24 日
Hi Chunhui, You don't need to use handles or guiData any longer if you are using App Designer. Instead you can store your data on the app as properties. To do this, in Code View in the Toolstrip there is a Insert Section. Push the property button. This will add a property to your code which you could name B1. To reference it in your code, type app.B1 instead of using handles and gui data.
Your new code should look something like this:
Up top after component properties read-only section,
properties (Access = private)
B1 % Audio File to play when button pushed
end
And in your button callback:
[filename, pathname] = uigetfile('*.mp3', 'Select audiofile');
[a,fs]=audioread([pathname filename]);
app.B1 = audioplayer(a,fs);
play(app.B1);
Let me know if this works for you. -Melissa
  1 件のコメント
Brian
Brian 2018 年 8 月 29 日
thank you! I've been looking for this for hours!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by