Interpolation Error using interp1
조회 수: 11 (최근 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!