当前位置:网站首页>Matlab画分段函数「建议收藏」
Matlab画分段函数「建议收藏」
2022-08-10 12:52:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
确定你需要的分段函数是怎样一个表达式,比如下面我的这个例子。
y = x,0 <= x <4;
2,4 <= x < 6;
5 – x/2, 6 <= x < 8;
1, x >= 8;
打开MATLAB软件,粘贴以下代码:
clc; clear all
x=0:0.01:10;
y=x.*(x>=0&x<4)+2*(x>=4&x<6)+(5-x/2).*(x>=6&x<8)+1*(x>=8);
plot(x,y,’r’,’linewidth’,2)
axis([0 10 0 2.1])
grid on
解释一下,代码的逻辑运算符是这个程序成败的关键,利用了判断逻辑数和向量之间的相乘,构造分段函数的表达式
点击运行,即可以得到分段函数的图像了。
注意:
前面的表达式和后面的逻辑判断相乘的时候,若前后均含有x,那么中间的乘号要是”.*”,即点+乘号。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/129979.html原文链接:https://javaforall.cn
边栏推荐
- Detailed explanation of es6-promise object
- Shell:数组
- BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection Paper Notes
- [Advanced Digital IC Verification] Difference and focus analysis between SoC system verification and IP module verification
- 广东10个项目入选工信部2021年物联网示范项目名单
- Loudi Sewage Treatment Plant Laboratory Construction Management
- 【目标检测】小脚本:提取训练集图片与标签并更新索引
- Ethernet channel 以太信道
- bgp dual plane experiment routing strategy to control traffic
- Redis上云迁移实践
猜你喜欢
Comparison version number of middle questions in LeetCode
Code Casual Recording Notes_Dynamic Programming_70 Climbing Stairs
跨域的五种解决方案
九宫格抽奖动效
系统的安全和应用(不会点安全的东西你怎么睡得着?)
ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]
Ethernet channel Ethernet channel
金山云要飘到哪里?
[Study Notes] Persistence of Redis
mSystems | Zhongnong Wang Jie Group Reveals the Mechanisms Affecting Soil "Plastic Interstitial" Microbial Communities
随机推荐
作业8.9 构建TCP协议的服务器
Keithley DMM7510 accurate measurement of ultra-low power consumption equipment all kinds of operation mode power consumption
A can make large data clustering method of 2000 times faster, don't poke
Codeforces Round #276 (Div. 1) D. Kindergarten
Guidelines for Sending Overseas Mail (2)
想问下大佬们 ,cdc oracle初始化一张300万的表任务运行着后面就这个错 怎么解决哇
系统的安全和应用(不会点安全的东西你怎么睡得着?)
想通这点,治好 AI 打工人的精神内耗
LeetCode·297.二叉树的序列化与反序列化·DFS·BFS
Wirshark common operations and tcp three-way handshake process example analysis
Open Office XML 格式里如何描述多段具有不同字体设置的段落
2022 Recruitment Notice for Academician Zhao Guoping Group of Shenzhen Institute of Advanced Technology, Chinese Academy of Sciences
shell:正则表达式及三剑客grep命令
jenkins数据迁移和备份
ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]
MYSQL误删数据恢复
Loudi Cosmetics Laboratory Construction Planning Concept
DNS欺骗-教程详解
LeetCode中等题之颠倒字符串中的单词
3DS MAX 批量导出文件脚本 MAXScript 带界面