Is there a quick way to shift real data points?

3 views (last 30 days)
I have discrete data points I collected with respect to time. I want to take the difference between a shift in time. In other words, shift all the data by some time and then subtract the original data from it. (ignoring points not in both graphs)
For example, this is what I'm trying to do. I doesn't work but I think you know what I mean:
LabResponse = csvread('scope_4.csv', 2, 0);
time = LabResponse(:,1);
delayedT = LabResponse(:,1) - 0.0005;
output = LabResponse(time, 2)-LabResponse(delayedT,2);

Accepted Answer

Jayaram Theegala
Jayaram Theegala on 17 Feb 2017
"delayedT" variable in the above MATLAB script can have decimal values, and if you try to use it for indexing with "LabResponse" variable, MATLAB will throw the "Subscript indices must either be real positive integers or logicals." error.
You may find the following code to be useful for achieving what you are trying to do:
if true
data = rand(1,10);
time = 1:10;
LabResponse = [time', data'];
shift = 2; %setting the shift to two time
output = LabResponse(1:length(LabResponse)-shift, 2) - LabResponse(shift+1:length(LabResponse),2)
end
As you can see from the "output" variable, its length is 8 (total length - shift = 8) and also, output(1) = data(1) - data(1+shift). I hope this helps.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!