フィルターのクリア

kindly help me correct my code. I want the s output to be same length as the output

2 ビュー (過去 30 日間)
f=60 ;
gg=tan(f);
H=6;
l=[-6:0.1:20];
x=l'
if (l<0)
s=0
end
if (l>=0&l<(H/gg))
s=l.*gg
end
if (l>=(H/gg))
s=H
end
cc=length(x)
ll=length(s)
plot(l,s,'r-')
Hello. I want to write this code such that the length of x and s are thesame so I can use it to draw lines. I have tried a couple of options but can't seem to figure it out, I only get one output of s. can anybody help me out. thank you.

採用された回答

Star Strider
Star Strider 2016 年 3 月 28 日
I suspect you mean the output to be the same length as the input. The easiest way is to use logical indexing, essentially adding two vectors that have the defined values over the ranges you want them to, and zero elsewhere. This produces the output vector you want.
This works:
l=[-6:0.1:20];
f=60 ;
gg=tan(f);
H=6;
sfcn = @(l,f,gg,h) [((l>=0) & (l<(H/gg))).*(l*gg) + (l>=(H/gg)).*h];
s = sfcn(l,f,gg,H);
figure(1)
plot(l, s, '-r')
  35 件のコメント
Star Strider
Star Strider 2016 年 4 月 7 日
My pleasure.
Brendan Atarigiya
Brendan Atarigiya 2016 年 6 月 23 日
hello Star Strider. I am here again with a problem. I want to write a loop to behave like I have below. hope you are doing good? thank you
guess initial y for l=0:0.2:1 y1=x*l +w/y end new_y=y1

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by