MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#" onclick="window._kiq.push(['set', { 'event': 'Turn off MT' }]);">ここ</a>」をクリックしてください。

0

Gui plot using Guide

George Diamond さんによって質問されました 2019 年 3 月 6 日
最新アクティビティ George Diamond さんによって コメントされました 2019 年 3 月 6 日
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 日
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 日
Hey Adam. I had shown the code above to show what produced the plot I showed earlier.
I updated the code as shown below and got some errors. please see below:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (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_avg = [];
grab_avg_time = datetime();
grab2_avg = [];
grab2_avg_time = datetime();
hPlot = plot(NaN, NaN, '--*');
hPlot2 = plot(NaN, NaN, '--o');
hasPlotBeenUpdated = false;
while handles.pushbutton1.Value == 1
handles.pushbutton1.BackgroundColor = '1 1 0';
grab_avg= strsplit((string(handles.dev.Query('FETC1:ARR:CW:POW?'))),','); %Fetch data from PM and convert to string
grab_avg = str2double(grab_avg(2)); %Average Power - Convert String to Number and place in array
grab_avg_time = datetime('now');
grab_avg_t = datenum(grab_avg_time);
grab2_avg= strsplit((string(handles.dev.Query('FETC2:ARR:CW:POW?'))),','); %Fetch data from PM and convert to string
grab2_avg = str2double(grab2_avg(2)); %Average Power - Convert String to Number and place in array
pause(str2double(handles.edit3.String))
hold on
if ~hasPlotBeenUpdated
hasPlotBeenUpdated = true;
set(hPlot,'XData',grab_avg_t,'YData',grab_avg);
hold(handles.axes2, 'on')
set(hPlot2,'XData',grab_avg_t,'YData',grab2_avg);
handles.grab_avg = grab_avg;
else
xdata = [get(hPlot,'XData'), grab_avg_t]; % update the x-data
ydata = [get(hPlot,'YData'), grab_avg]; % update the y-data
x2data = [get(hPlot2,'XData'), grab_avg_t]; % update the x2-data
y2data = [get(hPlot2,'YData'), grab_avg]; % update the y2-data
set(hPlot, 'XData', xdata, 'YData', ydata);
set(hPlot2, 'XData', x2data, 'YData', y2data);
end
grab2_avg= strsplit((string(handles.dev.Query('FETC2:ARR:CW:POW?'))),','); %Fetch data from PM and convert to string
grab2_avg = str2double(grab2_avg(2)); %Average Power - Convert String to Number and place in array
grab2_avg_time = datetime('now');
grab2_avg_t = datenum(grab2_avg_time);
pause(str2double(handles.edit3.String))
hold on
if ~hasPlotBeenUpdated
hasPlotBeenUpdated = true;
set(hPlot,'XData',grab2_avg_t,'YData',grab2_avg);
handles.grab2_avg = grab2_avg;
else
xdata = [get(hPlot,'XData'), grab2_avg_t]; % update the x-data
ydata = [get(hPlot,'YData'), grab2_avg]; % update the y-data
set(hPlot, 'XData', xdata, 'YData', ydata);
end
end
handles.pushbutton1.BackgroundColor = '0.3 0.75 0.93';
hold off
guidata(hObject,handles)
Error message shown below:
Error using matlab.graphics.chart.primitive.Line/set
Invalid or deleted object.
Error in Boonton_4500C_GUI_2_Continuous>pushbutton1_Callback (line 211)
set(hPlot,'XData',grab_avg_t,'YData',grab_avg);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Boonton_4500C_GUI_2_Continuous (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Boonton_4500C_GUI_2_Continuous('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
George Diamond 2019 年 3 月 6 日
Hey Adam, thanks so much for all your help. I've gotten it to work. I tweaked the code a little with both plot objects. I was not handles the individual objects properly at first. Thanks so much again.

サインイン to comment.

タグ

0 件の回答


Translated by