How to set maximum and minimum limit of signal in MATLAB code.
54 次查看(过去 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!