How can I include membership function inside a piece-wise function?

8 ビュー (過去 30 日間)
Kris
Kris 2017 年 8 月 10 日
回答済み: Robert U 2017 年 8 月 11 日
I'm trying to graph a piecewise function containing sigmoid membership function, however the result is always returned with dimension mismatch error. Any idea? Thanks.
Here's the code:
x= 0:.1:20;
y(0<=x & x<=10) = sigmf(x,[1 5]);
y(10<x & x<=20) = 1;
plot(x,y)

回答 (1 件)

Robert U
Robert U 2017 年 8 月 11 日
Hi Kris,
since you are using logical indexing, you must account for different sized vectors you want to write on (in your example the length of y is not the same as x). One possibility is to initialize the vector y by one and overwrite the values y(0<=x & x<=10):
x= 0:.1:20;
y = ones(1,length(x));
y(0<=x & x<=10) = sigmf(x(0<=x & x<=10), [1 5]);
plot(x,y)
Kind regards,
Robert

カテゴリ

Help Center および File ExchangeFuzzy Logic Toolbox についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by