Plotting and calculating difference

I have 2 matrix containing data of timestamps, 1 X Nth matrix I loaded them into the workspace and i want to plot the data on x axis and in the same figure. their size of matrix are different.
load('observations.mat');
load('control-times.mat');
index=880;
timestamp = ctrl_times(:,index:end);
obser_time = observation_times(:,1:end);
fig=figure;
hold on; axis equal;
plot(timestamp(1,:),'b*');
After plotting, how do i calculate the difference between data of the 2 matrices?
For example 1st data of timestamp - 1318496774.36108
however obser_time data starts from column 140 - 1318496774.90708
I would require looping if i am not wrong.
Thanks in advance.

댓글 수: 6

Walter Roberson
Walter Roberson 2012년 1월 13일
If the two matrices are 1 x N, N different between the two, then why does your code show them being accessed with a range index for both the first and second indices ? (:,index:end) and (:,1:end) are both syntaxes that suggest strongly that 2D matrices are being used.
Jw
Jw 2012년 1월 13일
In actual case, for my control-times,it originally has 1x11827 matrix however i only wanted to use the 880 column onwards and till the end of the control-times matrix
yes they are 2D matrices.
Walter Roberson
Walter Roberson 2012년 1월 13일
Is your ctrl_times a row vector, or is it a matrix for which size(ctrl_times,1) is greater than 1 ? If it is a row vector, why do you confuse things by indexing it with : as its first element?
If they are row vectors as you appear to indicate, then clearer code would be
timestamp = ctrl_times(index:end);
obser_time = observation_times;
Jw
Jw 2012년 1월 13일
oh ok my mistake of indexing it with :
Walter Roberson
Walter Roberson 2012년 1월 13일
Okay, so now please expand on what you mean by obser_time data starts from column 140 ? Do you mean the first 139 columns are NaN, or do you mean that column 1 of obser_time logically corresponds to column 140 of timestamp ?
Jw
Jw 2012년 1월 13일
basically what i need to do is plot the timestamp and obser_time and compare them. 1st to 139th values of obser_time are zeros.
I need to compare the both data. If there is a obser_time data that occurs before the next timestamp, find the difference in the time between the obser_time data and the previous timestamp.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2012년 1월 13일

0 개 추천

Hours to find out what you really wanted to do. Less than a minute to solve once that was known.
plot(timestamp, 'b*', obser_time, 'r+'); %your plot
padtimestamp = [0 timestamp inf];
[counts, binnums] = histc(obser_time, padtimestamp);
timestampdiff = obser_time - padtimestamp(binnums); %compared

댓글 수: 4

Jw
Jw 2012년 1월 15일
encounter this error while debugging. I suppose its because my timestamp is 1x10948 and my obser_time is 1x2072.
??? Error using ==> plot
Not enough input arguments.
Error in ==> timeintervals at 9
plot(timestamp, 'b*', obser_time, 'r+'); %your plot
Walter Roberson
Walter Roberson 2012년 1월 16일
plot(1:length(timestep), timestamp, 'b*', 1:length(obser_time), obser_time, 'r+'); %your plot
Jw
Jw 2012년 1월 17일
Now that i have gotten the difference between the obser_time to the previous timestamp, is it possible to also get the difference between the obser_time to the next timestamp??
Walter Roberson
Walter Roberson 2012년 1월 17일
nextdiff = padtimestamp(binnums+1) - obser_time;
Note if there is an observ_time which is exactly the same or greater than the largest timestamp, then this nextdiff time will be infinity.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

Jw
2012년 1월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by