I ran your script by replacing your hardware data with random number and I observed that measurements being concatenated to the graph. In the while loop, you are measuring voltage from the hardware twice without updating the count variable which could be the reason for first voltage reading being replaced by second voltage reading during each iteration.
Graphing a Voltage Plot in real time
3 次查看(过去 30 天)
显示 更早的评论
I am trying to obtain a real time plot of Voltage pulses acquired from a Keithley 6487 Voltage Source. I was able to get the graph to show and update in real time, showing points at "5V" when 5 volts were applied through SCPI commands and at "0V" when 0 volts were applied. However, after each pulse, the previous one gets deleted as shown below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162068/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162069/image.png)
I want each subsequent measurement to be concatenated on the graph as if it were a square wave pulse as shown below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162070/image.jpeg)
I have included my code for the plot below. Does anyone have any suggestions?
%%Plot
figureHandle = figure('NumberTitle','off',... 'Name','Voltage Characteristics',... 'Color',[0 0 0],'Visible','off');
% Set axes axesHandle = axes('Parent',figureHandle,... 'YGrid','on',... 'YColor',[0.9725 0.9725 0.9725],... 'XGrid','on',... 'XColor',[0.9725 0.9725 0.9725],... 'Color',[0 0 0]); hold on;
voltage_sweep=plot(axesHandle,time,voltage,'Marker','.','LineWidth',1,'Color',[0 1 0]);
xlim(axesHandle,[min(time) max(time+0.001)]);
% Create xlabel xlabel('Time','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create ylabel ylabel('Voltage in V','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create title title('Voltage Characteristics','FontSize',15,'Color',[1 1 0]);
%% Set the time span and interval for data collection
stopTime= input('Input the date and endtime for the experiment.\n'); %Input has to be in 'MM/DD HH:MM:SS' format
timeInterval = 0.001;
%% Collect data count = 1;
while ~isequal(datestr(now,'mm/DD HH:MM:SS'),stopTime)
time(count) = datenum(clock);
a=query(obj1, 'MEASure:CURRent:DC?'); %Meausres current
I=a(2:13); %Output of a is a long string, only 2:13 are needed
if str2double(I)> 15E-14 %Checks if current is above threshold
fprintf(obj1,':SOURce:VOLTage:LEVel:IMMediate:AMPLitude 0'); %sets voltage amplitude of instrument to 0
break
else
fprintf(obj1,':SOURce:VOLTage:LEVel:IMMediate:AMPLitude 0'); %sets voltage amplitude of instrument to 0 for a half second pulse
pause(.5)
fprintf(obj1,':SOURce:VOLTage:LEVel:IMMediate:AMPLitude?'); % Measures Voltage at this timepoint
voltage(count) = fscanf(obj1,'%f',1); %#ok<SAGROW>
set(voltage_sweep,'YData',voltage,'XData',time);
set(figureHandle,'Visible','on');
datetick('x','mm/DD HH:MM:SS')
fprintf(obj1,':SOURce:VOLTage:LEVel:IMMediate:AMPLitude 5'); %sets voltage amplitude of instrument to 5 for a half second pulse
pause(.5)
fprintf(obj1,':SOURce:VOLTage:LEVel:IMMediate:AMPLitude?'); % Measures Voltage
voltage(count) = fscanf(obj1,'%f'); %#ok<SAGROW>
set(voltage_sweep,'YData',voltage,'XData',time);
set(figureHandle,'Visible','on');
datetick('x','mm/DD HH:MM:SS')
end
pause(timeInterval);
count = count +1;
end
0 个评论
回答(1 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!