MATLAB: How to restrict plots of two variables to a chosen value of a third variable

MATLAB: How to restrict plots of two variables to a chosen value of a third variable

cutsplot

I have imported a 3-column table and assigned a variable name to each column. Is there an easy way to plot two columns against each other (plot(x,y,’*’)) restricted to a particular value in the third column?

Best Answer

  • A = [1 2 1;
    2 3 2;
    3 4 1;
    4 5 2;
    5 6 1;
    6 7 2];
    indexToPlot = A(:,3)==1;
    figure
    plot(A(indexToPlot,1),A(indexToPlot,1),'*-');
    I just did it with an array, but if your variables are in table, the same sort of logic applies.
  • Add a Comment

    Your email address will not be published. Required fields are marked *