本帖最后由 可怜小白 于 2020-5-9 13:53 编辑
我想在GUI里用uigetfile打开音频文件,然后在“xuanzedakai”里显示文件名,然后分析后在“shibiejieguo”显示结果。可是程序运行后shibiejieguo没有显示,程序报错:无法执行赋值,因为左侧和右侧的元素数目不同。求大佬指教问题出在哪?
如果可以也请指教一下这样分析音频对不对。谢谢!
接触matlab的第四天,小白中的小白,有些基础问题还不是很明白。求各位稍微耐心一点,救救孩子
以下是代码:
function shibie_Callback(hObject, eventdata, handles)
% hObject handle to shibiejieguo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName]=uigetfile('*.m4a','选择分析的音频');
file=[PathName,FileName];
tt=strcat(get(handles.xuanzedakai,'String'),FileName);
set(handles.xuanzedakai,'String',tt);
[y,fs]=audioread(file);
sound(y,fs);
counter=length(handles.numsig)/820;
for i=1:counter
f=fft(handles.numsig((i-1)*820+1:1*410),8192);
a=abs(f);
p=a.*a/8192;
num(1)=find(p(1:1000)==max(p(1:1000)));
num(2)=1000+find(p(1000:1700)==max(p(1000:1700)));
if(num(1)<730)
row=1;
elseif(num(1)<810)
row=2;
elseif(num(1)<900)
row=3;
else
row=4;
end
if(num(2)<1300)
col=1;
elseif(num(2)<1400)
col=2;
else
col=3;
end
if((row==1)&&(col==1))
newnum=strcat(get(handles.shibiejieguo,'String'),'1');
set(handles.shibiejieguo,'String',newnum);guidata(hObject,handles);
elseif((row==1)&&(col==2))
newnum=strcat(get(handles.shibiejieguo,'String'),'2');
set(handles.shibiejieguo,'String',newnum);guidata(hObject,handles);
elseif((row==1)&&(col==3))
newnum=strcat(get(handles.shibiejieguo,'String'),'3');
set(handles.shibiejieguo,'String',newnum);guidata(hObject,handles);
elseif((row==2)&&(col==1))
newnum=strcat(get(handles.shibiejieguo,'String'),'4');
set(handles.shibiejieguo,'String',newnum);guidata(hObject,handles);
elseif((row==2)&&(col==2))
newnum=strcat(get(handles.shibiejieguo,'String'),'5');
set(handles.shibiejieguo,'String',newnum);guidata(hObject,handles);
elseif((row==2)&&(col==3))
newnum=strcat(get(handles.shibiejieguo,'String'),'6');
set(handles.shibiejieguo,'String',newnum);guidata(hObject,handles);
elseif((row==3)&&(col==1))
newnum=strcat(get(handles.shibiejieguo,'String'),'7');
set(handles.shibiejieguo,'String',newnum);guidata(hObject,handles);
elseif((row==3)&&(col==2))
newnum=strcat(get(handles.shibiejieguo,'String'),'8');
set(handles.shibiejieguo,'String',newnum);guidata(hObject,handles);
elseif((row==3)&&(col==3))
newnum=strcat(get(handles.shibiejieguo,'String'),'9');
set(handles.shibiejieguo,'String',newnum);guidata(hObject,handles);
elseif((row==4)&&(col==2))
newnum=strcat(get(handles.shibiejieguo,'String'),'0');
set(handles.shibiejieguo,'String',newnum);guidata(hObject,handles);
end
end