direction Link to heading

  • Sign in to MathWorks at https://matlab.mathworks.com/.
  • Notice available hours for MATLAB Online (basic).
  • Open MATLAB Online (basic).
  • Create New Script.
  • Press CTRL+S to save.
  • Give a name for the empty file about to be saved, e.g. plot_color_marker_line.m.
  • Click Save button.
  • Start to write the code.
  • Run the code.
  • Save figure as PDF.
  • Download it to local folder.
  • Upload it to https://cloudconvert.com/pdf-to-svg.
  • Convert it to PDF.
  • Download SVG file.

code Link to heading

% create empty arrays
x1 = []; y1 = [];
x2 = []; y2 = [];
x3 = []; y3 = [];
x4 = []; y4 = [];
x5 = []; y5 = [];
x6 = []; y6 = [];

% initial and incremental values
x = 0;
dx = 0.25;

% generate data
while x <= 10
    % data 1
    if 0 <= x & x <= 2
        x1 = [x1 x];
        f1 = x^2;
        y1 = [y1 f1];
    end

    % data 2
    if 2 <= x & x <= 3
        x2 = [x2 x];
        f2 = 4 * (x - 2) + 4;
        y2 = [y2 f2];
    end

    % data 3
    if 3 <= x & x <= 5
        x3 = [x3 x];
        f3 = 12 - (x - 5)^2;
        y3 = [y3 f3];
    end
    
    % data 4
    if 5 <= x & x <= 6
        x4 = [x4 x];
        f4 = 12;
        y4 = [y4 f4];
    end

    % data 5
    if 6 <= x & x <= 8
        x5 = [x5 x];
        f5 = 12 - (x - 6)^2;
        y5 = [y5 f5];
    end
    
    % data 6
    if 8 <= x & x <= 10
        x6 = [x6 x];
        f6 = 6 + 2*(x - 9)^2;
        y6 = [y6 f6];
    end
    
    x = x + dx;
end

% plot results
plot( ...
    x1, y1, '-or', ...
    x2, y2, '-*g', ...
    x3, y3, '-sb', ...
    x4, y4, '-+m', ...
    x5, y5, '-dk', ...
    x6, y6, '-xc' ...
);
grid on;
xlabel("x");
ylabel("y");

 

0246810x024681012y

linespec Link to heading

LineSpecLineMarkerColor
-or-or red
-*g-* *g green
-sb-sb blue
-+m-+ +m magenta
-dk-dk black
-xc-x ×c cyan

equations Link to heading

  • For 0x20 \le x \le 2 y=x2.(1)\tag{1} y = x^2.

    % data 1
    if 0 <= x & x <= 2
        x1 = [x1 x];
        f1 = x^2;
        y1 = [y1 f1];
    end
    
  • For 2x32 \le x \le 3 y=4(x2)+4.(2)\tag{2} y = 4(x-2) + 4.

    % data 2
    if 2 <= x & x <= 3
        x2 = [x2 x];
        f2 = 4 * (x - 2) + 4;
        y2 = [y2 f2];
    end
    
  • For 3x53 \le x \le 5 y=12(x5)2.(3)\tag{3} y = 12 - (x - 5)^2.

    % data 3
    if 3 <= x & x <= 5
        x3 = [x3 x];
        f3 = 12 - (x - 5)^2;
        y3 = [y3 f3];
    end
    
  • For 5x65 \le x \le 6 y=12.(4)\tag{4} y = 12.

    % data 4
    if 5 <= x & x <= 6
        x4 = [x4 x];
        f4 = 12;
        y4 = [y4 f4];
    end
    
  • For 6x86 \le x \le 8 y=12(x6)2.(5)\tag{5} y = 12 - (x - 6)^2.

    % data 5
    if 6 <= x & x <= 8
        x5 = [x5 x];
        f5 = 12 - (x - 6)^2;
        y5 = [y5 f5];
    end
    
  • For 8x108 \le x \le 10 y=6+2(x9)2.(6)\tag{6} y = 6 + 2(x - 9)^2.

    % data 6
    if 8 <= x & x <= 10
        x6 = [x6 x];
        f6 = 6 + 2*(x - 9)^2;
        y6 = [y6 f6];
    end
    
  • And for all ranges

y={x2,0x2,4(x2)+4,2x3,12(x5)2,3x5,12,5x6,12(x6)2,6x8,6+2(x9)2,8x10.(7)\tag{7} y = \left\{ \begin{array}{cc} x^2, & 0 \le x \le 2, \newline 4(x-2) + 4, & 2 \le x \le 3, \newline 12 - (x - 5)^2, & 3 \le x \le 5, \newline 12, & 5 \le x \le 6, \newline 12 - (x - 6)^2, & 6 \le x \le 8, \newline 6 + 2(x - 9)^2, & 8 \le x \le 10. \end{array} \right.