好的,所以我查看了有关此错误的其他问题,但没有一个适用于我的。我正在尝试将一个简单的音乐播放器包含在我的 MATLAB 程序中,但每次尝试运行它时都会出现错误
Attempt to reference field of non-structure array.
Error in Beam_Deflection_GUI_3_Music>Play_Music_Call (line 388)
n = get(S.listMusic,'Value');
Error while evaluating uicontrol Callback
我不知道为什么,但这是我的代码:
MusicChoice = {'Message in A Bottle','Roxanne'};
S.Pa4 = uipanel('title','Music',...
'FontSize',12,...
'BackgroundColor','white',...
'Units','pixels',...
'Position',[25 80 280 425],...
'Parent',S.fh,...
'fontweight','b',...
'FontAngle','italic',...
'visible','off');
S.listMusic = uicontrol('parent',S.Pa4,...
'style','popupmenu',...
'String',MusicChoice);
S.Play = uicontrol('parent',S.Pa4,...
'style','push',...
'string','Play',...
'units','pix',...
'pos',[100 100 20 20],...
'callback',@Play_Music_Call);
function [] = Play_Music_Call(varargin)
S = varargin{1};
n = get(S.listMusic,'Value');
MusicChoice = {'Message in A Bottle','Roxanne'};
mChoice = MusicChoice(n,1);
[y, Fs, nbits] = wavread(mChoice);
S.player = audioplayer(y, Fs, nbits);
play(S.player)
end