adnan - the hold on call in your pushbutton callback is causing the axes to appear within your GUI. According to hold, this function retains plots in the current axes so that new plots added to the axes do not delete existing plots. I think that because the current figure is your GUI with no axes, then the software just creates the axes within it. Your pushbutton callback code is being called every five seconds and is creating a new figure every time. Given your inclusion of hold on, I'm guessing that you instead want to have just one figure and update its axes whenever the timer expires. In addition to this, you should not use the pushbutton callback as your timer expiry callback because the signatures are different - a handles structure is not one of the input parameters, hObject is not the handle to the pushbutton control, etc. You should separate these two callbacks. Initialize your timer expiry function callback as
handles.a = timer('ExecutionMode','fixedRate','Period',5,'TimerFcn',{@timerCallback,hObject});
where we pass in hObject, the handle to the GUI, as the third input. Now, create your timer callback as
function timerCallback(hObject,eventdata,hGui)
handles = guidata(hGui);
if ~isfield(handles,'hFig')
handles.hFig = figure();
handles.hAxes = axes('Parent',handles.hFig);
guidata(hGui,handles);
hold(handles.hAxes,'on');
end
conn = database('', '', '', 'org.sqlite.JDBC', 'jdbc:sqlite:C:\Users\Uchiha Madara\Desktop\New folder (2)\PedelecManager\Server\sample.db');
curs = exec(conn,'select table1.XAchse from table1');
curs1 = fetch(curs)
data2=curs1.Data;
plot(handles.hAxes,data2);
Note how we check to see if the figure has already been created (and so is a field of the handles structure). If not, then we create the figure, create the axes for that figure, update the handles structure, and apply the hold. We can then query your database and update the axes with the new data.
Try the above and see what happens!
NOTE that since you are querying the data every five seconds, having the pushbutton do the same may not be necessary. If you have added the button so that the user can update the axes faster than the five second rate, then just take the code that would be common to the timer and pushbutton callbacks and put into a separate function that both functions would then call.