loop implementation with two conditions
2 次查看(过去 30 天)
显示 更早的评论
I have a time series data sampled at 100 ms. I would like to pick samples every 1 sec or when difference between 2 consecutive samples is more than 10 and then implement a logic inside this condition. How do I use both these together as an 'if' condition?
Thanks!
2 个评论
Guillaume
2018-1-3
"How do I use both these together as an 'if' condition?"
Most likely, if is the wrong tool. Can you give an example of "the logic inside this condition"?
回答(1 个)
Guillaume
2018-1-3
Something like this would work:
samples = randi([0 20], 1, 1000); %demo data
indices1s = 1:100:numel(samples); %indices at every 1 s
indicesdiff = find(abs(diff(samples)) > 10); %indices of 1st sample when consecutive sample difference is greater than 10.
newsamples = samples(unique([indices1s, indicesdiff, indicesdiff+1])); %indicesdiff+1 to get the 2nd of the two samples when diff is greater than 10
It's all vectorised operations, so no if needed.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!