MATLAB: How to draw horizontal line in the yaxis using the existing code

drawgraphlineMATLABmaxminplotplottingscatterscatter plotxaxisyaxis

Hi there,
So I've got this code at the moment, which opens a file (using my really smaller scale data) then filters all the NaN values and removes duplications.
Now I have drawn a scatter plot (bottom of my code). I was hoping to see a horizontal line across y axis. I have set a minimum and maximum threshold 'y1Thresh' so that once my data has been plotted, I can see how much data is out of bounds (low or high threshold). So if anyone can please help me how to use my existing code to show a horizontal line on Y-axis, that would be greatly appreciated. Please Help!! 🙁
%--FIND NaN ROWS THEN DELETE ENTIRE ROW
PCBAllDataSet = readtable('testfile5.csv');
%imports the only columns needed
PCBRequiredCol = PCBAllDataSet(:,{'PcbTestID','TestTime','PcbID','Verify12VInput','VerifyCurrentDraw','Rail5V'});
%remove row that contains NaN value
PCBRemoveNaNRow = rmmissing(PCBRequiredCol);
%--REMOVE ROW DUPLICATIONS'y1
%create another table for keyset and valueset
%duplications will be removed as the table is made
newTable = containers.Map('KeyType','char','ValueType','any');
%forloop to assign key and value set on every row
for i = 1:size(PCBRemoveNaNRow,1)
%key for hashMap to partner with valueSet
keyID = char(table2cell(PCBRemoveNaNRow(i,3)));
%current(i) row, 2nd column to end column
valueSet = PCBRemoveNaNRow(i,2:end);
%setting value pairs
newTable(keyID) = valueSet;
end
%shows the
voltsInput = newTable.values;
allDataSet = [];
for j = 1:numel(voltsInput)
allDataSet = [allDataSet; voltsInput{j}];
end
%--Verify12VInput vs. Date/Time, Scatter Plot
figure;
x1 = allDataSet{:,1}; %date and time
y1 = allDataSet.Verify12VInput; %gets all column values of Verify12VInput
%--HEEELLPPP HEREEE
%--sets the min and max THRESHOLD so I can see how data in the graph
% is out of bounce(out of the line)
%--hoping to see a (min,max) horizontal line from y axis
y1Thresh = [11.75, 12.25];
scatterPlot = scatter(x1,y1);

Best Answer

What exactly is "a (min,max) horizontal line from y axis"? The posted code does not help to understand, what you are asking for. Maybe this helps already:
axesH = axes('NextPlot', 'add'); % same as: hold on
y1Thresh = [11.75, 12.25];
scatterPlot = scatter(x1,y1);
drawnow;
xL = axesH.XLim;
line(xL, y1Thresh([1,1]))
line(xL, y1Thresh([2,2]))
By the way, did you search in the forum for "draw horizontal line" already? It is a good idea to use the existing answers.