简体   繁体   English

在Matlab中有多步逐点函数化?

[英]Many step picewise function in Matlab?

What is the simplest way to generate piecewise level function like the following 生成分段级别函数的最简单方法是什么,如下所示

在此处输入图片说明

Suppose, I know height (y-value) and length (horizontal) of each level in a matrix 假设我知道矩阵中每个级别的高度(y值)和长度(水平)

>> C=[2,4,1,-3;2,1.5,0.7,2.8]

C =

    2.0000    4.0000    1.0000   -3.0000
    2.0000    1.5000    0.7000    2.8000

Ie first row says level level, and the second -- it's horizontal length. 即第一行表示水平,第二行表示水平长度。

Also I would like to have some interpolation between levels. 我也想在级别之间进行一些插值。

I use this tool . 我使用这个工具 For example, given this set of piecewise functions: 例如,给定这组分段函数:

 x < -5, y = 2 
-5 <= x < 0, y = sin(x) 
 0 <= x < 2, y = x.^2 
 2 <= x < 3, y = 6 
 3 <= x, y = inf 

So, as a function of any variable x, just call it like this: 因此,作为任何变量x的函数,只需像这样调用它:

y = piecewise_eval(x,[-5 0 2 3],{2,'sin(x)','x.^2',6,inf});

use 采用

stairs([0 cumsum(C(2,:))], [C(1,:) C(1,end)]);

If you want to change the values in between or plot it differently you can get the coordinates by 如果要更改之间的值或以其他方式绘制它,可以通过以下方法获取坐标

[x, y] = stairs([0 cumsum(C(2,:))], [C(1,:) C(1,end)]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM