How can I make data points in one variable NaN according to another time-based variable?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
balsip
le 28 Oct 2015
Réponse apportée : Star Strider
le 28 Oct 2015
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.
0 commentaires
Réponse acceptée
Star Strider
le 28 Oct 2015
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical 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!