How can I get the maximum difference in the specific range?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
KSSV
2019-5-8
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 个评论
Walter Roberson
2019-5-8
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 .
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!