命令行操作之函数绘图(MATLAB基础)

吴恩达机器学习第五章笔记

x=[0:0.01:0.98] %生成00.98范围的一组数,间隔0.01
y=sin(2*pi*x)
plot(x,y) %生成x为横轴,y为纵轴的图

在这里插入图片描述

hold on %保持原来的图像
y1=sin(2*pi*x+0.1)
plot(x,y1,'b') %在原来的图上添加新图,用蓝色画线
xlabel('time') %添加横轴标签
ylabel('value') %添加纵轴标签
legend('y','y1') %给曲线添加标签
title('my plot') %给图像添加标题

在这里插入图片描述

print -dpng 'myplot.png' %保存图片,名称为“myplot.png”
close %关闭图像
figure(1);plot(b,y)
figure(2);plot(b,y1)
close
close

在这里插入图片描述

subplot(1,2,2) %开一个窗口,可横放2张图,选定第二张图的位置
plot(b,y1) %在第二张图的位置画图
subplot(1,2,1) %选定第一张图的位置
plot(b,y) %画图

在这里插入图片描述

axis([0.5 1 -2 2]) %改变第一张图的横轴范围为0.51,纵轴范围为-22

在这里插入图片描述

clf %清除图像

在这里插入图片描述

A=magic(5) %生成一个行列对角线相加都相等的5阶矩阵
A =

    17    24     1     8    15
    23     5     7    14    16
     4     6    13    20    22
    10    12    19    21     3
    11    18    25     2     9
imagesc(A)

在这里插入图片描述

imagesc(A),colorbar,colormap gray

在这里插入图片描述

imagesc(magic(20)),colorbar,colormap gray

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42899627/article/details/105885479