Divide time into milliseconds when input changes

2 views (last 30 days)
Deep Patel
Deep Patel on 21 Jul 2020
Edited: Image Analyst on 22 Jul 2020
input = [0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0]
time = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
You can see at 7th sec my input changes and it becomes 1. So, I want to divide my TIME 7th sec into 2^n/1000 sec (n=2 to 9) and at a same time I want to print my input 1, 8 more times. after that it becomes normal at the 8th sec, 9th sec, and 10th sec. But at 11th sec the input changes again, so do the same thing.
Can any one help me please?
Thank you.
  2 Comments
Image Analyst
Image Analyst on 22 Jul 2020
Nobody understands what you want. So you want an extra batch of times (a new time vector segment) inserted between 7 and 8 for the time array that are spaced a delta-time of 2^n/1000? Ok, that can be done, but what is n? And why does n only range from 2 to 9.
Looks like nothing changes at 11 - it's "input" value was 0 just like it was for time=10. Why do you say there is a change there? And so you want another time vector inserted in between 11 and 12 with a delta of 2^n/1000 seconds? And what is n in that case? And why does nothing happen at 15 when "input" changes from 0 to 1?
And input is a built-in function name so you should not use it as a variable name.

Sign in to comment.

Answers (1)

waqas
waqas on 21 Jul 2020
Statment is not that clear but may be this is what you want to do:
i = [1,10:10:20] % assuming your signal is repeating after 10 values and ends at 20 values
%You can change the length to 100 if you want.
j = 1:(length(i) -1) % This is for the iteration loop so that it would work on longer signal size too
n = 2:9;
printOut = ones(8,2); %first column would change but second would be ones as you mentioned in the
for jj = j
inputSig = input(i(jj):i(jj+1)); %Takes first 10 points of input signal
changePoint = min(find(inputSig ==1)) %If change in signal is observed by change in value from 0 to 1
% then this line find the minimum point at which this change takes place.
printOut(:,1) = 2.^n/1000; % You can take it outside the loop as the values remains the same
printOut
end

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by