Interpolation Error using interp1
12 次查看(过去 30 天)
显示 更早的评论
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.
>>
0 个评论
采纳的回答
Star Strider
2015-4-28
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 个评论
Star Strider
2015-4-28
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
2015-4-28
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’.
更多回答(1 个)
Image Analyst
2015-4-29
Try
x = double(x);
y = double(y);
to make sure they're doubles like interp1() said it wanted.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!