how to plot a two-dimensional heaviside function

14 ビュー (過去 30 日間)
Ksenia
Ksenia 2014 年 8 月 13 日
コメント済み: Ksenia 2014 年 8 月 13 日
Hi, everybody! I'm trying to plot some heaviside function like that:
x=0:1000;
y=0:500;
z=0:25;
R=25*(heaviside(x-40)-heaviside(x-240))*(heaviside(y-40)-heaviside(y-160));
but I always get an error sound like
error using * Inner matrix dimensions must agree.
I was trying to rewrite an expression like this:
R=25*(heaviside(x-40)-heaviside(x-240)).*(heaviside(y-40)-heaviside(y-160));
but I've got the same mistake with using .*.... What can you suggest? And also how to plot functions like that?

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 13 日
編集済み: Azzi Abdelmalek 2014 年 8 月 13 日
x=0:1000;
y=0:500;
z=0:25;
a=25*(heaviside(x-40)-heaviside(x-240)),
b=(heaviside(y-40)-heaviside(y-160));
out=bsxfun(@times,a.',b)
  1 件のコメント
Ksenia
Ksenia 2014 年 8 月 13 日
My first attempt was right. I've got a great plot by changing code like this:
[x,y]=meshgrid(0:30:1000, 0:30:500);
R=25*(heaviside(x-40)-heaviside(x-240)).*(heaviside(y-40)-heaviside(y-160));

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

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by