Tiled graphs can be displayed using the tiledlayout and nexttile functions. Call the tiledlayout function to create a 2-by-1 tiled map layout. Call the nexttile function to create the axes objects ax1 and ax2. Plot random data in each axes. Add a legend to the upper plot by specifying ax...
上述代码将绘制100个随机生成的点,并设置点标记为圆形。同时,设置标题为"Scatter plot",x轴标签为"x",y轴标签为"y"。- 绘制多条曲线:```matlab x = 0:0.1:2*pi;y1 = sin(x);y2 = cos(x);plot(x, y1, 'r', x, y2, 'b--');title('Sine and cosine waves');xlabel('x');ylabel...
This example shows how to plot two sine waves with different line styles by adding a line specification string to eachx,ypair. Plot the first sine wave with a dashed line using'--'. Plot the second sine wave with a dotted line using':'. x = linspace(0,2*pi,100); y1 = sin(x);...
plot(x, y); title('Sine Wave'); xlabel('X-axis'); ylabel('Y-axis'); 2、多条线图:绘制多条线在同一图中。 matlab Copy code x = 1:10; y1 = sin(x); y2 = cos(x); plot(x, y1, 'r', x, y2, 'b'); title('Sine and Cosine Waves'); legend('Sine', 'Cosine'); 3、...
使用plot 和hold on 将两个图形数据绘制在同一个图形窗口中: matlab figure; plot(x, y1); hold on; % 保持当前图形,继续添加新的图形 plot(x, y2, 'r--'); % 以红色虚线绘制余弦波 title('Sine and Cosine Waves'); legend('Sine Wave', 'Cosine Wave'); % 添加图例 hold off; % 释放保持...
Hz") ax.plot(time,sinewave1) ax.set_xlabel("Time(s)") ax.set_ylabel("Amplitude") ax2 =...
For example, plot two sine waves, and add a dashed zero line by calling the yline function. Then create a legend, and exclude the zero line by specifying its label as ''. x = 0:0.2:10; plot(x,sin(x),x,sin(x+1)); hold on yline(0,'--') legend('sin(x)','sin(x+1)'...
plot(x, y2, '--b', 'LineWidth', 2); % 绘制蓝色虚线 title('Sine and Cosine Waves'); xlabel('X-axis'); ylabel('Y-axis'); legend('Sine', 'Cosine'); hold off; 这段代码生成一个包含正弦波和余弦波的折线图,并使用不同的线型和颜色区分两个数据集。
Create a stairstep plot of two sine waves evaluated at different values. Specify a unique set of x-values for plotting each data series. x1 = linspace(0,2*pi)'; x2 = linspace(0,pi)'; X = [x1,x2]; Y = [sin(5*x1),exp(x2).*sin(5*x2)]; ...
Example 2: Plot Spectrogram of Sum of two Sine WavesThe code we have is as follows −t = 0:0.001:2; z = sin(2*pi*50*t) + sin(2*pi*150*t); spectrogram(z); title('Spectrogram of Sum of Two Sine Waves'); In this example, the signal z is created by summing two sine ...