当前位置:网站首页>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
边栏推荐
- M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
- Interface Automation Testing Basics
- 2022 Recruitment Notice for Academician Zhao Guoping Group of Shenzhen Institute of Advanced Technology, Chinese Academy of Sciences
- Redis 定长队列的探索和实践
- 学习日记9
- Calculate the number of combinations recursively
- 3DS MAX batch export file script MAXScript with interface
- YTU 2295: KMP模式匹配 一(串)
- 娄底石油化工实验设计、建设规划概述
- 跨域的五种解决方案
猜你喜欢
LeetCode·297.二叉树的序列化与反序列化·DFS·BFS
LeetCode中等题之比较版本号
Keithley DMM7510 accurate measurement of ultra-low power consumption equipment all kinds of operation mode power consumption
专有云ABC Stack,真正的实力派!
交换机的基础知识
Ethernet channel Ethernet channel
ABAP file operations involved in the Chinese character set of problems and solutions for trying to read
Basic knowledge of switches
浙大、阿里提出DictBERT,字典描述知识增强的预训练语言模型
Nanodlp v2.2/v3.0 light curing circuit board, connection method of mechanical switch/photoelectric switch/proximity switch and system state level setting
随机推荐
鸿蒙开发从hello world开始
没有接班人,格力只剩“明珠精选”
DNS欺骗-教程详解
进程和计划任务管理
The recursive recursive Fighting_ silver study ah but level 4
Calculate the number of combinations recursively
燃炸!字节跳动成功上岸,只因刷爆LeetCode算法面试题
Code Casual Recording Notes_Dynamic Programming_70 Climbing Stairs
【iOS】Organization of interviews
2022-08-09:以下go语言代码输出什么?A:否,会 panic;B:是,能正确运行;C:不清楚,看投票结果。 package main import ( “fmt“ “syn
shell:常用小工具(sort、uniq、tr、cut)
CodeForces - 811A
Open Office XML 格式里如何描述多段具有不同字体设置的段落
矩阵键盘&基于51(UcosII)计算器小项目
[Study Notes] Persistence of Redis
网络安全——XSS之被我们忽视的Cookie
Jenkins修改端口号, jenkins容器修改默认端口号
C#中导入其它自定义的命名空间
递归递推之Fighting_小银考呀考不过四级
神了!阿里数据库专家纯手写了这份604页的Oracle+MySQL攻坚指南