Is it possible to create a stairstep function?
古いコメントを表示
Hi all,
I am trying to create a function that emulates what is seen below, I don't think it may be possible with stairstep but I am unsure. Does anyone know how this could be done? As I want an equation that I can have an input x value and then output a y value from the function.
% Stairstep function
x = [0:15];
y = [19,19,19,19,19,25,25,25,25,25,25,19,19,19,19,19];
figure
stairs(x,y)
ylim([0,30]);
Much appreciated
3 件のコメント
Image Analyst
2017 年 2 月 14 日
Let's say you have a function f() and you input a single scalar value, x. Let's say you send in 9 for the sake of illustration. How should the function know what to return? Should it return 173? How about 4.5? Sure you can define a function but you have to tell it what to return. So far I don't know what you want to send in as "x", and how the function should determine an output "y", and how stairs() has anything to do with it. If you want stairs() just use stairs().
John Chilleri
2017 年 2 月 14 日
Not sure I understand, unless you're speaking of exactly the x and y you have above. In that case,
function y = foo(x)
vec = [ones(1,5)+18 ones(1,6)+24 ones(1,5)+18];
y = vec(x+1);
end
which accepts any x in [0,15].
Tyler Bikaun
2017 年 2 月 14 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!