Interpolation Error using interp1

52 views (last 30 days)
I'm using a script to take these x and y values from a .txt file. At this point in the script the variables are assigned the fid is closed... When I code further, I'm trying to interpolate a user entered value which is called 'userx'.
Below, though, I am just trying to get it to interpolate at 100. I don't understand where my syntax error is.
>> x
x =
0
20
22
30
33
52
52
67
84
101
103
111
116
132
141
159
162
168
171
173
>> y
y =
8477
11886
11384
6087
7871
3003
1941
9213
10981
2179
2219
507
1593
8880
11650
4392
6118
4437
2094
1961
>> interp1(x,y,100) Error using interp1 (line 130) Values must be of type double or single.
>>

Accepted Answer

Star Strider
Star Strider on 28 Apr 2015
Check the data types of x and }y}. My guess is that they are either cells or strings.
If they are cells, you can convert them to double arrays with:
x = x{:};
y = y{:};
  4 Comments
Star Strider
Star Strider on 28 Apr 2015
Jorge Bastillo’s ‘Answer’ moved here...
Also tried using cell2mat... Didn't work either.
>> a=cell2mat(x)
Cell contents reference from a non-cell array object.
Error in cell2mat (line 42)
cellclass = class(c{1});
Star Strider
Star Strider on 28 Apr 2015
That would mean to me that your conversion from cell to numeric with:
x=data{1};
y=data{2};
was successful (and correct), and that the problems are with non-numeric entries in ‘x’ and ‘y’.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 29 Apr 2015
Try
x = double(x);
y = double(y);
to make sure they're doubles like interp1() said it wanted.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!