Is there a quick way to shift real data points?

2 vues (au cours des 30 derniers jours)
Real Name
Real Name le 9 Fév 2017
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);

Réponse acceptée

Jayaram Theegala
Jayaram Theegala le 17 Fév 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.

Plus de réponses (0)

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!

Translated by