MatLab 二维图像绘制基础

MatLab 二维图像绘制基础

plot 描点绘图

java 复制代码
%%
% 二维绘图 ,plot进行描点,步长越小,越平滑
x = [1:9];
y = [0.1:0.2:1.7];
X = x + y*i; % 复数
plot(X)

plot绘制矩阵

c 复制代码
%%
% 当X Y 为矩阵时,对应矩阵中的元素依次绘制
t = 0:0.01:2*pi;
t = t.';%转置 为列
x = [t,t,t]; %n行3列
y = [sin(t),sin(2*t),sin(0.5*t)]; % n行3列
plot(x,y) % 三条曲线 ,有多少列,就多少条曲线

linspace 生成线性间距向量

c 复制代码
%%
% 绘制多条曲线 
% linspace 生成线性间距向量
clear;
clc;
x1 = linspace(0,2*pi,10); %  0    0.6981    1.3963    2.0944    2.7925    3.4907    4.1888    4.8869    5.5851    6.2832
x2 = linspace(0,2*pi,20);
x3 = linspace(0,2*pi,200);%  步长不一样,直观的看到曲线的平滑度

y1 = sin(x1);
y2 = sin(x2);
y3 = sin(x3);

plot(x1,y1,x2,y2,x3,y3);

fplot 绘制表达式

c 复制代码
%%
% fplot 绘制表达式 图像
fplot(@(x)sin(1./x),[0,0.2]);
%hold on;
fplot(@(t)t*sin(t),@(t)t*cos(t),[0,10*pi]);

semilogx 对数坐标图

c 复制代码
%% 
% semilogx 对数坐标图
x = logspace(-1,2); % 0.1-100
y = x;
semilogx(x,y); % log10为底

polarplot 极坐标

c 复制代码
%%
% 极坐标
 theta = 0:0.01:2*pi; % 0-2pi
 rho = sin(theta) .* cos(theta);
 polarplot(theta,rho);

bar 条形图

c 复制代码
%%
% 条形图
x = [2021,2022,2023];
y = [10,20;20,30;100,200];
bar(x,y);

histogram 直方图

c 复制代码
%%
% 直方图
x = randn(1000,1);
nbins = 25;
h = histogram(x,nbins);
counts = h.Values;

pie 饼图

c 复制代码
%%
%饼图
x = [1:2:9];% 从1开始每次+2,  1     3     5     7     9
pie(x);

scatter 散点图

c 复制代码
%%
%散点图
t = 0:pi/50:2*pi %每次+0.0628
x = 16*sin(t).^3;
y = 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t);
scatter(x,y,'yellow','filled');

quiver 矢量类图形

c 复制代码
%%
%矢量类图形
A = [4,5];
quiver(0,0,A(1),A(2));

属性设置

c 复制代码
%%
% 属性设置
x = linspace(0,2*pi,200);
y = [sin(x);sin(2*x);sin(0.5*x)];
plot(x,y)
%横纵坐标限制
axis([0,6.5,-1.5,1.5]);
%标题
title("三个正弦函数y=sin{\theta}","FontSize",15);
xlabel("X");
ylabel("Y","Rotation",0);
% 文字说明
text(2.5,sin(2.5),'sin(x)');
text(2.5,sin(2*2.5),'sin(2x)');
%图例
legend('sin(x)','sin(2*x)','sin(0.5x)');

图形保持

r 复制代码
%%
% 图形保持
t = linspace(0,2*pi,200);
x = sin(t);
y = cos(t);
plot(x,y,'b');
axis equal;%横坐标与纵坐标相等
hold on;
x1 = 2*sin(t);
y1 = 2*cos(t);
plot(x1,y1,'r');

添加图形标注

c 复制代码
%% 
%课后小练
% 已知向量A、B,求A+B,用矢量图表示并用所学知识添加图形标注
% A = [4,5];
% B = [-10,10];
A = [4,5];
B = [-10,10];
C = A + B;
quiver(0,0,A(1),A(2));
hold on;
quiver(0,0,B(1),B(2));
quiver(0,0,C(1),C(2));
hold off;
title("矢量相加");
xlabel("X");
ylabel("Y","Rotation",0);
text(A(1),A(2),'A');
text(B(1),B(2),'B');
text(C(1),C(2),'C');
grid on; %显示网格线
相关推荐
小浣熊熊熊熊熊熊熊丶6 小时前
《Effective Java》第25条:限制源文件为单个顶级类
java·开发语言·effective java
啃火龙果的兔子6 小时前
JDK 安装配置
java·开发语言
星哥说事6 小时前
应用程序监控:Java 与 Web 应用的实践
java·开发语言
等....7 小时前
Miniconda使用
开发语言·python
zfj3217 小时前
go为什么设计成源码依赖,而不是二进制依赖
开发语言·后端·golang
醇氧7 小时前
org.jetbrains.annotations的@Nullable 学习
java·开发语言·学习·intellij-idea
Java&Develop7 小时前
Aes加密 GCM java
java·开发语言·python
weixin_462446237 小时前
使用 Go 实现 SSE 流式推送 + 打字机效果(模拟 Coze Chat)
开发语言·后端·golang
JIngJaneIL7 小时前
基于springboot + vue古城景区管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
敲敲了个代码7 小时前
隐式类型转换:哈基米 == 猫 ? true :false
开发语言·前端·javascript·学习·面试·web