How can I make data points in one variable NaN according to another time-based variable?

1 次查看(过去 30 天)
I have one variable (X) for which I need to remove data (convert to NaN) for a ten-minute time span when another variable (Y) switches.
Some background: (Y) stays constant until it switches from 3 to, say, 4. For a ten-minute period after this process of switching begins, the data is unreliable.
I'm very green at all this, and I don't know how to phrase the time component, but could certainly use guidance with all of it.

采纳的回答

Star Strider
Star Strider 2015-10-28
One possibility:
t = 0:100; % Create Time Vector (Minutes)
X = 2 + sin(0.1*pi*t);; % Create ‘X’
Y = 3*ones(size(t));
Y(17) = 4; % Create ‘Y’
switch_idx = find(Y > 3); % Detect Index OF ‘Y Switch’
X(switch_idx:switch_idx+9) = NaN; % Set ‘X’ To NaN For 10 Minutes
figure(1)
subplot(2,1,1)
plot(t, X)
grid
subplot(2,1,2)
plot(t, Y)
grid
This is simplified by design. You might need additional code to calculate the index range for your 10 minute ‘time out’ depending on your sampling frequency.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by