interpolate text file data onto different time axis

Hello,
I have a text file which when imported creates a 226 x 2 matrix, with time being the (:,1) and SSH being (:,2). I want to compare and plot this data on some data I have created which is on a 723 x 1 axis. I have tried interp1 and I keep getting all NaN's apart from a few numbers here:
interp1(data(:,1), data(:,2), createddata) so like interp1(226x1, 226x1, 723x1)
I also tried making my own xaxis (1:723) and trying that but it didn't work...
Can someone help me?
thanks in advance! Michael

7 件のコメント

Michael
Michael 2014 年 7 月 28 日
so basically I aim to get all my data on a 723x1 axis..and preferably combine my two 226 x 2 matrices so that time and SSH is shown without plot vs.
dpb
dpb 2014 年 7 月 28 日
Show a short snippet of the data or at least indicate what format the times are in...a little tough w/ no info to say specifically what could be wrong.
Michael
Michael 2014 年 7 月 28 日
1994.12054794521 0.723087167530352
1994.20273972603 0.868722680919340
1994.28401826484 0.926712390684742
1994.36803652968 -0.432860295716313
1994.45114155251 -1.68076906196128
1994.53515981735 -1.91932285662016
1994.61917808219 -2.44475990592223
1994.70319634703 -2.64274970700751
1994.78721461187 -3.74283405134685
1994.87031963470 -3.30721413609148
1994.95433789954 -2.57712850554302
1995.03835616438 -1.16617618188867
etc...
Michael
Michael 2014 年 7 月 28 日
this is an example of the two columns (one space between shown on here..)
Michael
Michael 2014 年 7 月 28 日
as for my created data, there is no time, just 1:723 index numbers
Michael Haderlein
Michael Haderlein 2014 年 7 月 28 日
Your createddata vector is 1:723? As all numbers in the first column (=x) are outside the interval 1:723, it's clear that you only get NaNs. You need to provide times at your createddata vector.
Michael
Michael 2014 年 7 月 28 日
I have just tried using the time values (given in a separate file) from 1993-2012 in a 723x1 matrix but I still get NaN's. Is this what you meant I should do? maybe I have misunderstood you.
t file = 723 x 1 (1.9930:1.206)

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

 採用された回答

dpb
dpb 2014 年 7 月 28 日

1 投票

As the other Michael says, "Houston, we have a problem!"
How do you want these data to line up with each other? How does the time relationship of the first point in the above data set relate to the first point in your series of length 723? Likewise for the last. If you're trying to stretch the 226 over 723 points just on a 1:1 basis between first and last, you don't need to use interp1, just set the time for the 226 points via
t1=linspace(1,723,226);
or, generically,
t1=linspace(1,length(series2),length(series1));
If there's some other way they're to correlate, need to define what that relationship is and if the time in these data is significant create a time vector between those two points similarly except use the time values instead of 1:N

その他の回答 (2 件)

Star Strider
Star Strider 2014 年 7 月 28 日

1 投票

If you’re getting NaN values from interp1, you are probably extrapolating.
Change your call to interp1 to:
ynew = interp1(data(:,1), data(:,2), createddata, 'linear', 'extrap');
and see if that does what you want. (Change ‘ynew’ to your own variable. I used it here simply to complete the line correctly.)
Michael
Michael 2014 年 7 月 28 日

0 投票

Thanks, linspace worked a treat!

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

2014 年 7 月 28 日

回答済み:

2014 年 7 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by