Why can't I plot a spectrogram in my GUI?!?

조회 수: 7 (최근 30일)
Jack Latham
Jack Latham 2016년 11월 16일
편집: Greg Dionne 2016년 11월 17일
So I have a gui that allows me to record audio, and then either plot a time history or a spectrogram of the data depending on a pop-up menu choice; but I can't get the spectrogram to plot. There is only on set of axis. My code for this section is -
function Start_Callback(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fs = str2num(get(handles.Fs,'string'));
bits = str2num(get(handles.nbits,'string'));
tend = str2num(get(handles.tstart,'string'));
w = 1000;
ptype = get(handles.popupmenu,'value');
AudioRaw = audiorecorder(fs,bits,1); %define recording parameters
recordblocking(AudioRaw,tend); %record audio
th = getaudiodata(AudioRaw);
dt = 1/fs;
t = 0 :dt: length(th)*dt - dt;
% spectrogram(th,w,w/2,[],fs,'yaxis')
if ptype == 1
plot(t,th);
xlabel('Time, s')
ylabel('Amplitude, v')
elseif ptype == 2
spectrogram(th,w,w/2,[],fs,'yaxis')
end
This gives me a number of errors:
Struct contents reference from a non-struct array object.
Error in spectrogram>displayspectrogram (line 282)
if strcmp(hRotate.State,'off')
Error in spectrogram (line 237)
displayspectrogram(t,f,Pxx,isnormfreq,faxisloc,esttype,threshold);
Error in quickRecord>Start_Callback (line 103)
spectrogram(th,w,w/2,[],fs,'yaxis')
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in quickRecord (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)quickRecord('Start_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
I've checked the data etc and the spectrogram should plot fine. Any tips would be great!!! I'm pretty flummoxed.
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2016년 11월 16일
Jack - which version of MATLAB are you using? Can you create a spectrogram from the command line (outside of your GUI) using an example found at spectrogram?

댓글을 달려면 로그인하십시오.

답변 (1개)

Greg Dionne
Greg Dionne 2016년 11월 17일
편집: Greg Dionne 2016년 11월 17일
Looks like you're trying to redirect the auto-generated debug plot of the spectrogram to a dedicated figure, and it's failing because you don't have the "Rotate 3D" button defined in your figure.
You can rotate the spectrogram plot into a nice 3D image by clicking the rotation button in the debug plot. If you don't see it, in your figure's "View" menu check the View->FigureToolbar item, then click on the icon that has a cube circumscribed with a counterclockwise arrow (next to the "hand" icon). Then drag around in the axes.
Normally, spectrogram will generate a new figure with the button enabled. Make sure that button exists in your GUI before calling spectrogram.

카테고리

Help CenterFile Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by