How can I get the maximum difference in the specific range?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to find the value of the maximum difference of the wave, but I would like to eliminate some part of the graph.
In this case, I would like to delete the range from 0.0 to 0.5 and get the maximum value from 0.5 to 3.
I have no idea how to execute the above process.
t = 0:1/1000:3;
q1 = sin(2*pi*7*t).*exp(-t/2);
plot(t,q1)
[up,lo] = envelope(q1,100,'analytic');
hold on
plot(t,up,'-',t,lo,'--')
hold off
envelope(q1,300)
maxDiff = peak2peak(up-lo);
disp(maxDiff)
4 commentaires
Réponse acceptée
KSSV
le 8 Mai 2019
Let t, data be your time and data. You have two options:
First option
% Remove the specified data, this will reduce the length of your arrays.
idx = data >= 0 & data <= 0.5 ;
t(idx) = [] ;
data(idx) = [] ;
Second option
% Make the unwanted data to NaN, this will not change the length of the array
idx = data >= 0 & data <= 0.5 ;
data(idx) = NaN ;
3 commentaires
Walter Roberson
le 8 Mai 2019
Where did you obtain the line
for idx = (1:20)-1
? I do not see anyone having suggested that.
MATLAB indices start with 1. Your 1:20 would be [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]. Then you subtract 1 to get [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19] . Then you try to use that first value, 0, as an index, which is a problem.
Perhaps you are accustomed to Python, which indexes from 0 but has the odd range() construct that generates 0 to N-1 .
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!