clear; % clear variables %constants% comport = "COM6"; % port to connect with baudRate = 9600; % baud read and write rate MOT = 3; % array index for the MOT output readTime = 50000; % time of which the figure remains active trailingNum = 10; % number of trailing dots on the scatter plot mulThresh = 5; % multiplicative threshold to determine if the drop is within the NES range nesMoveRate = 10.23; % movement rate of the NES output figurexLen = 100; % length of the printed figure %program% if ~isempty(instrfind) % if com link is found fclose(instrfind); % close com link delete(instrfind); % end s = serialport(comport, baudRate); % connect to com link figure(1); % display figure 1 i = 1; % iterative variable while (i < readTime) % while we have been running for less than readTime out = readline(s); % read a line from the serial monitor stringtok = strsplit(out); % split the string voltageMOT = stringtok(MOT); % tokenize the split and set it to a variable voltageMOTD(i) = str2double(voltageMOT); % cast the variable as a double vPlotMOT = voltageMOTD; % set another variable to entire array of MOT data zeroArray(1:1+figurexLen) = 0; % create an array of length 100 filled with zeros vPlotMOT = [zeroArray vPlotMOT]; % concatenate the zero filled array with our current data plot(vPlotMOT(i:i+99)); % display scatter plot of data title('Motor Current in Realtime'); % set title of the diplayed figure xlabel('Time'); % set the x labbel for the displayed figure ylabel('Current'); % sethte y label for the diplsayed figure ylim([-1000 1000]); % limit the graph to 1023 on the y axis i = i + 1; % iterate end clear s; % clear the com link if ~isempty(instrfind) % if com link is found fclose(instrfind); % close com link delete(instrfind); % end