フィルターのクリア

how to plot substracted data

1 回表示 (過去 30 日間)
Daniel Barzegar
Daniel Barzegar 2014 年 6 月 20 日
コメント済み: Daniel Barzegar 2014 年 6 月 20 日
if true
function test(data,t)
figure;
fprintf(1,'%s %d\n', t, length(data));
plot((data(2:end,2)-data(1:end-1,2))./1000000000,data(:,3),'r-');
hold on;
plot((data(2:end,2)-data(1:end-1,2))./1000000000,data(:,4),'g-');
plot((data(2:end,2)-data(1:end-1,2))./1000000000,data(:,5),'b-');
title(t);
dt = (data(2:end, 2)- data(1:end-1, 2))./1000000000;
figure;
hist (dt, [0:0.002:0.5]);
title(t);
end
hi all, i try to subtract the values as shown above so that i can get the time in seconds(the 2nd column in the data contains timestamps in nanoseconds) as shown below:
1 144274932861 -0.16280572 9.49301 -0.36391866
2 144279571533 0.10295067 9.557653 -0.46926352
3 144284942626 0.2908955 9.586384 -0.5650316
4 144289581298 0.2837129 9.657013 -0.51595044
5 144294952392 0.09816227 9.685743 -0.46088383
6 144299591064 -0.09696517 9.736021 -0.33638534
7 144304962158 -0.19871874 9.750386 -0.32680854
8 144309631347 -0.12090719 9.783905 -0.40940848
9 144314971923 0.075417355 9.828198 -0.47524905
10 144319610595 0.14963761 9.831789 -0.46447513 etc
so at the end of the day i want to get the timestamp(2nd column) in secs.
However, the error message that i get is: Matrix dimensions must agree.
Error in test (line 5) plot(data(2:end,2)-data(1:end,2),data(:,3),'r-');
any idea? thanks!

採用された回答

Andrew
Andrew 2014 年 6 月 20 日
編集済み: Andrew 2014 年 6 月 20 日
So from what I see it looks like you are trying to simply subtract one timestamp from the previous 1. In that case all you need to do is
plot([0;data(2:end,2)-data(1:end-1,2)],data(:,3),'r-');
Also, It's not a good idea to use true as a variable because it's a key word in matlab for a logical true.
EDIT: I realized you would have a mismatch in size between the two vectors so you need to add a 0 at the beginning. This makes sense because your first measurement should happen at time 0
  6 件のコメント
Andrew
Andrew 2014 年 6 月 20 日
If you have an old version of MATLAB you may need:
plot(data(1:end,2)-data(1,2)*ones(size(data(1:end,2))),data(:,3),'r-')
Daniel Barzegar
Daniel Barzegar 2014 年 6 月 20 日
yes, that's it! thanks :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by