Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
horizon
horizon am 8 Mai 2019
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 Kommentare
horizon
horizon am 8 Mai 2019
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) = [];

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KSSV
KSSV am 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 Kommentare
horizon
horizon am 8 Mai 2019
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;
Walter Roberson
Walter Roberson am 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 .

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by