Search code examples
matlabplot

matlab, plotting 2 vecctors as a list, how can I give them different line types and colours using this syntax


I have checked SO and ML help but cannot see a solution to this.

using this syntax

E = 10; % amplitude
sample_1_hz = 1000;
sample_2_hz = 11000;
fs = 10000; % sample rate in Hz
Samples = 100;
time_scale = (0:Samples-1)'/fs;
sig_1 = E*sin(2*pi*time_scale*sample_1_hz);
sig_2 = E*sin(2*pi*time_scale*sample_2_hz);

plot(time_scale,[sig_1 sig_2]);

grid('on');
xlabel('Time');
ylabel('Amplitude');
legend('1000 Hz', '11000 Hz');

how can I alter the lines to have different line styles and colors?


Solution

  • the two lines coincide in every point in time_scale in the example code you posted (plot their difference sig_1-sig_2 and see the values in the 1e-13), so the only way to see both of them is to make one "dashed" and the other "solid" so you can see one on top of the other , or add a marker to one of them. for example,

    plot(time_scale, sig_1 ,'-',time_scale,sig_2,':o','LineWidth',2 );
    

    enter image description here