How can I get the maximum difference in the specific range?

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

From what you want to delete the range from 0.0 to 0.5 ?
I would like to delete data from 0.0 to 0.5.
data(data >= 0 & data <= 0.5) = [];
Thank you for your answer.
When I opened the array t, it has these consequtive data.
t = [0 0.00100000000000000 0.00200000000000000 0.00300000000000000 0.00400000000000000 0.00500000000000000 0.00600000000000000 0.00700000000000000 0.00800000000000000 0.00900000000000000 0.0100000000000000 0.0110000000000000 0.0120000000000000 0.0130000000000000 ....]
I can understand that your answer substitutes data range from 0 to 0.5 null, but in this case, what does it applied to data?
data(data >= 0 & data <= 0.5) = [];

Connectez-vous pour commenter.

 Réponse acceptée

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

The result of the max value of differences were same both with and without elimination.
>> cutSentwave
1.8245
code without elimination
t = 0:1/1000:3;
q1 = sin(2*pi*7*t).*exp(-t/2);
% Make the unwanted data to NaN, this will not change the length of the array
%idx = t >= 0 & t <= 0.5 ;
%t(idx) = NaN ;
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)
code wth elimination
t = 0:1/1000:3;
q1 = sin(2*pi*7*t).*exp(-t/2);
% Make the unwanted data to NaN, this will not change the length of the array
idx = t >= 0 & t <= 0.5 ;
t(idx) = NaN ;
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)
t = 0:1/1000:3;
q1 = sin(2*pi*7*t).*exp(-t/2);
% Make the unwanted data to NaN, this will not change the length of the array
for idx = (1:20)-1
t(idx) = nan;
q1(idx) = nan;
end
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)
If I write the above, since idx is array index and it is required to reduce data for y-axis. However, I got an error message.
Array indices must be positive integers or logical values.
Error in cutSentwave (line 6)
t(idx) = nan;
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 .

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Identification dans Centre d'aide et File Exchange

Produits

Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by