How to set maximum and minimum limit of signal in MATLAB code.
41 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Usman Taya
il 18 Gen 2019
Modificato: Usman Taya
il 20 Gen 2019
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 Commenti
Risposta accettata
Omer Yasin Birey
il 18 Gen 2019
Modificato: Omer Yasin Birey
il 18 Gen 2019
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 Commenti
Omer Yasin Birey
il 20 Gen 2019
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.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!