How to set maximum and minimum limit of signal in MATLAB code.
36 ビュー (過去 30 日間)
古いコメントを表示
I need to set maximum and minimum value of variables. For example,
x3= x1 + x2
where
maximum value of x1 = 3
minimum value of x1 = 0
maximum value of x2 = 2.5
minimum value of x2 = -1
I didn't understand that how i can implement it in MATLAB codes.
0 件のコメント
採用された回答
Omer Yasin Birey
2019 年 1 月 18 日
編集済み: Omer Yasin Birey
2019 年 1 月 18 日
Hi Usman, you can use one of the codes below. However, I recommend the first one, because no loop is necessary here.
x1Max = 3;
x1Min = 0;
x2Max = 2.5;
x2Min = -1;
x1(x1>x1Max) = x1Max;
x1(x1<x1Min) = x1Min;
x2(x2>x2Max) = x2Max;
x2(x2<x2Min) = x2Min;
x3 = x1 + x2;
or
x1Max = 3;
x1Min = 0;
x2Max = 2.5;
x2Min = -1;
x3 = zeros(length(x1),1);
for i = 1:length(x1)%or length x2 since they must have the same dimensions.
if x1(i)>x1Max
x1(i) = x1Max;
elseif x1(i)<x1Min
x1(i) = x1Min;
end
if x2(i)>x2Max
x2(i) = x2Max;
elseif x2(i)<x2Min
x2(i) = x2Min;
end
x3(i) = x1(i)+x2(i);
end
6 件のコメント
Omer Yasin Birey
2019 年 1 月 20 日
Hi Usman, apparently you haven't assigned any value to x1. It is hard to understand from here what it should have been given to x1, x2 or x3. Is there any text you can share that explains what code should do? So I can understand fully and help.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!