필터 지우기
필터 지우기

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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by