Search code examples
matlabplotdata-analysiscurve

Which type of MATLAB plot would produce spikes on a curve based on certain condition?


I have a 29736 x 6 table in MATLAB. The 6th column of the table consists of zeroes and ones. I would like a plot between the Sample No (1 to 29736 of Table) and the 6th column (ones and zeroes), such that there is a nice spike whenever a 1 occurs and a regular curve when 0 occurs. Can someone suggest what line of code/function can do this, and how to systematically go about it?

EDIT:

I used the following code and got an unwanted result (a solid blue block):

stem(table_fault_test_data.Fault_Condition, 'Marker', 'none');
set(gca, 'YLim', [0 2]);       % Adjust the y-axis range

I basically want to refer to the 6th column of my table which contains ones and zeroes, and plot spikes for only the ones.


Solution

  • Are you perhaps looking for a stem plot? You can make one without a marker, so you get spikes for ones and zero for zeroes:

    data = rand(1, 100) < 0.2;     % Some random sample data
    stem(data, 'Marker', 'none');  % Make the stem plot
    set(gca, 'YLim', [0 2]);       % Adjust the y-axis range
    

    enter image description here