How to draw horizontal line in my yaxis using my existing code

1 visualización (últimos 30 días)
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);

Respuesta aceptada

Jan
Jan el 16 de En. de 2019
Editada: Jan el 16 de En. de 2019
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.
  1 comentario
Andrea Del Rosario
Andrea Del Rosario el 30 de En. de 2019
Yes :( But I kept getting stuck with errors, Im very new to Matlab. Thank you so so much!

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 31 de En. de 2019
If you're using release R2018b or later use the yline function.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by