As for your above code not doing what you expect, look closely at what you are trying to set with the new XData and YData
if (pressure>200)&(pressure<500)
set(handles,'XData','g',[get(handles,'XData') x]);
set(handles,'YData','g',[get(handles,'YData') a]);
else if (pressure >300)&(pressure<700)
set(handles,'XData','o',[get(handles,'XData') x]);
set(handles,'YData','o',[get(handles,'YData') a])
else
set(handles,'XData','r',[get(handles,'XData') x]);
set(handles,'YData','r',[get(handles,'YData') a])
end
end
The above code has too many ends (unless you are missing an if in there) so please remove the last one. And look at any of the
handles is a structure of handles to the GUI controls (start, uitable1, axes1, axes2, axes3, etc.) and is not a handle to particular graphics object like a plot which is what I think you are intending it to be.
For example, you would need something like
handles.hPlot1 = plot(handles.axes1, NaN, NaN);
guidata(hObject, handles);
In the above we have created an "empty" plot on axes1, and then save the graphics handle to the handles structure (using guidata). Note that this code could be written in your GUI's opening function. Now, in the timer callback (or in what you have done above), you would do
if (pressure>200)&(pressure<500)
set(handles.hPlot1,'XData',[get(handles.hPlot1,'XData') x], ...
'YData',[get(handles.hPlot1,'YData') a], ...
'MarkerEdgeColor', 'g');
else if (pressure >300)&(pressure<700)
set(handles.hPlot1,'XData',[get(handles.hPlot1,'XData') x], ...
'YData',[get(handles.hPlot1,'YData') a], ...
'Marker','o');
else
set(handles.hPlot1,'XData',[get(handles.hPlot1,'XData') x], ...
'YData',[get(handles.hPlot1,'YData') a], …
'MarkerEdgeColor', 'r');
end
Note that your above code changes the current and all of the past pressure data which may not be desirable.
Note also, that you haven't defined a.
Best Answer