0
votes

I'm trying to give 2 points from user and showing the spectrogram between those points, I do it with following codes successfully, But I don't know why get I below Errors?

Also I want to know, if I want to put a reset button in my code to revert the plot to initial state how can I do that?

function From_Callback(hObject, eventdata, handles)

handles.from=str2double(get(hObject, 'String'));
guidata(hObject,handles);


function From_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function To_Callback(hObject, eventdata, handles)

handles.to=str2double(get(hObject, 'String'));
guidata(hObject,handles);



function To_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function Zoomb_Callback(hObject, eventdata, handles)

minY=min(str2double(get(handles.Samplef, 'String')))*1000;
maxY=max(str2double(get(handles.Samplef, 'String')))*1000;
axes(handles.axes2);
axis([handles.from, handles.to, minY, maxY ]);

Error using set Bad property value found. Object Name : axes Property Name : 'YLim' Values must be increasing and non-NaN.

Error in axis>LocSetLimits (line 208) set(ax,...

Error in axis (line 94) LocSetLimits(ax(j),cur_arg);

Error in M_player>Zoomb_Callback (line 202) axis([handles.from, handles.to, minY, maxY ]);

Error in gui_mainfcn (line 96) feval(varargin{:});

Error in M_player (line 42) gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)M_player('Zoomb_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating uicontrol Callback

1
Well in your call to axis([...] the limits for the y-axis are minY to maxY, which are identical. Therefore you get the error message. Maybe you made an error in fetching either minY or maxY?Benoit_11
Thank you. I want only the x axis scaling change and y remind in it's scaling, but don,t know how can I do that! I've tried to get the y scales from spectrogram but didn't succeed :(user3305284

1 Answers

0
votes

Ok according to your comment, here is how you can change only the scale of the x axis and keep the same range for the y axis.

In order to get the actual limits of the y axis from axes2, you can use the following:

ylimit = get(handles.axes2,'YLim')

The values are in the same format as that of the axes, i.e. pixel, normalized, etc.

This will give you a 2-element vector containing the min and max values. Therefore, in the call to axis you make in your code, you could use this to keep the range of the y-axis constant:

ylimit = get(handles.axes2,'YLim')
axis([handles.from, handles.to, ylimit(1), ylimit(2)]);

Hope that is what you meant!