Gui plot using Guide
显示 更早的评论
Hi all,
I got some help with a code that lets me plot a variable in real time. However, I am having problem plotting 2 variables or inputs on th same plot. When I try to plot both inputs, it somehow combines the value and plots a single point for both. Not as famaliar with this plot method and not a 100% sure if it's even possible to do what I'm trying to.
Does you all have suggestions or other things to try?
Please let me know.
Thanks.
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.edit1.String = str2double(string(handles.dev.Query('SENS1:CORR:OFFS?'))); %Grab channel offset
handles.edit2.String = str2double(string(handles.dev.Query('SENS2:CORR:OFFS?'))); %Grab channel offset
grab_max = [];
grab_max_time = datetime();
hPlot = plot(NaN, NaN, '--*');
hasPlotBeenUpdated = false;
while handles.pushbutton2.Value == 1
grab_max= strsplit((string(handles.dev.Query('FETC1:ARR:CW:POW?'))),','); %Fetch data from PM and convert to string
grab_max = str2double(grab_max(4)); %Average Power - Convert String to Number and place in array
grab_max_time = datetime('now');
grab_max_t = datenum(grab_max_time);
pause(str2double(handles.edit3.String))
hold on
if ~hasPlotBeenUpdated
hasPlotBeenUpdated = true;
set(hPlot,'XData',grab_max_t,'YData',grab_max);
handles.grab_max = grab_max;
else
xdata = [get(hPlot,'XData'), grab_max_t]; % update the x-data
ydata = [get(hPlot,'YData'), grab_max]; % update the y-data
set(hPlot, 'XData', xdata, 'YData', ydata);
end
end
hold off
13 个评论
Adam
2019-3-6
"When I try to plot both inputs, it somehow combines the value and plots a single point for both"
I don't really understand what you mean by this. do you have screenshots, or some other way of explaining it? The general technique seems fine, glancing over the code, although you need a
guidata( hObject, handles )
at the bottom of your function to ensure handles.grab_max is updated properly, but that is not relevant to the particular problem you are describing as far as I can see.
George Diamond
2019-3-6
Adam
2019-3-6
Updating plots using the method above will add to the same line, that is its purpose as it is far more efficient to do this than to keep replotting the same data just with an extra point added.
If what you want is a seperate plot though then you will need another plot instruction instead.
George Diamond
2019-3-6
Adam
2019-3-6
It's up to you if you want another axes, but if you want to visualise them in the same place then you can use the same axes, just with an appropriately positioned
hold( hAxes, 'on' )
before you do a new
plot( hAxes, ... )
instruction, where hAxes is the handle of your axes.
George Diamond
2019-3-6
Adam
2019-3-6
Are there supposed to be 2 plots there? I can only see one.
George Diamond
2019-3-6
Adam
2019-3-6
If they are being plotted as two explicit plot instructions this should not happen, even if you are updating each one as you go using the above syntax, you should be updating 2 distinct line objects with the points for each.
George Diamond
2019-3-6
Adam
2019-3-6
You still only seem to have
hPlot
there and you are giving it both your grab_avg and grab_avg_t data. You need to distinct plot handles to update, one for each, if I understand correctly the result you want.
George Diamond
2019-3-6
George Diamond
2019-3-6
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
