Undefined function or variable 'hObject' in app designer
1 回表示 (過去 30 日間)
古いコメントを表示
[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.
0 件のコメント
回答 (1 件)
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
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!