I have two sets of values, A and B. and I would to write a Heaviside function such that it returns 0, when A is less than B, and returns 1, when A is greater than B.

 採用された回答

Star Strider
Star Strider 2018 年 2 月 19 日

0 投票

I am not certain what result you want.
Try this:
A = randi([2 3], 1, 30); % Create ‘A’
B = randi([2 3], 1, 30); % Create ‘B’
T = 1:numel(A); % Create Time Reference
HF = @(a,b) (a > b); % Function
figure(1)
plot(T, A, T, B)
hold on
plot(T, HF(A,B), 'LineWidth',2)
hold off
ylim = [-0.1 3.1];
legend('A', 'B', 'HF(A,B)', 'Location','E')

4 件のコメント

Brian
Brian 2018 年 2 月 19 日
Thanks Star. My result would 1 or 0 depending on my input (as described in the question). Thanks again!
Star Strider
Star Strider 2018 年 2 月 19 日
My pleasure.
My code does what you described in your question.
Please run it. If it does not produce the result you want, please provide an example of sample inputs and desired output.
Brian
Brian 2018 年 2 月 19 日
The code runs perfectly. Thank you
Star Strider
Star Strider 2018 年 2 月 19 日
My pleasure.
If my Answer helped you solve your problem, please Accept it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumerical Integration and Differential Equations についてさらに検索

質問済み:

2018 年 2 月 19 日

コメント済み:

2018 年 2 月 19 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by