plot

i have a column of data that has 100 points I also have a time column which only has 10 points basically data was sampled at 10Hz, but my time vector contains time value for every 10th sample.
How would I plot this? I run into a problem since the vectors are of different size.

2 Comments

Baba
Baba on 17 Nov 2011
i'm thinking i can add aditional time points in my time matrix
to make it's length equal to data matrix.
I have:
time=[1,2,3,4,5,6,7,8,9,10]
I need:
time=[1,1.1,1.2,1.3,1.4........10]
not sure how to do that either.
Walter Roberson
Walter Roberson on 17 Nov 2011
Duplicate is at http://www.mathworks.com/matlabcentral/answers/21564-plot

Sign in to comment.

Answers (1)

bym
bym on 17 Nov 2011

0 votes

use interp1 to resample your time vector to match the data vector

12 Comments

Baba
Baba on 17 Nov 2011
my actual time vector is:
[200123,200124,200125...
it's actual time, so when it gets up 200159, next value is 200200,
not sure how i'd use interp1 in this case
bym
bym on 17 Nov 2011
convert it using datenum perhaps?
Baba
Baba on 17 Nov 2011
when i plot my figure, i'd like to look at a point and see it's coordinates in terms of data value and time value, if i convert it to datenum i won't see the actual time value i think
bym
bym on 17 Nov 2011
you can plot it using 'datetick' which plot is actual time value
Walter Roberson
Walter Roberson on 17 Nov 2011
If that is your "actual time vector" and the value after 200159 is 200200, then you do not appear to be missing any points.
If the first value in the vector of sampled time values is the time for the very first data point, then use
NewTimes = Time(1):Time(end)+9;
plot(NewTimes, Data);
If the first value in your vector of sampled times is instead the time for the 10th data point, then use
NewTimes = Time(1)-9:Time(end);
plot(NewTimes, Data);
Baba
Baba on 18 Nov 2011
So i'd like to create a vector that fills in spaces between 200159 and 200200 by 2000159.1,2000159.22011159.3... like that.
Baba
Baba on 18 Nov 2011
and the first value in the vector is samled time on first data point.
bym
bym on 18 Nov 2011
Am I interpreting you correctly: 200159 represents hh:mm:ss and you want to get hh:mm:ss.s ?
Baba
Baba on 18 Nov 2011
yes and .s represents some fraction of a second, say .1 of a second.
bym
bym on 18 Nov 2011
then my original suggestion of converting to a datnum, using interp1, and plot using 'datetick' stands.
Baba
Baba on 18 Nov 2011
seems that there should be a way to create n empty spaces between each matrix element and then fill them in.
Walter Roberson
Walter Roberson on 18 Nov 2011
There is no method of creating empty spaces in a vector.
Note that if interp1() is used, use the 'linear','extrap' options.
You will also have to calculate the data point endpoints. But if you have already gone through the trouble of figuring out the endpoints, then you might as well use linspace()
Use the code from your other thread, but for the Time values, instead of passing in your 200159 and so on, pass in
Time = datenum(str2num(YourTimes.'));
and use the datetick suggestion,
datetick('x','HH:MM:SS.FFF')

Sign in to comment.

Categories

Asked:

on 17 Nov 2011

Community Treasure Hunt

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

Start Hunting!