How to spline 163 data points into 100 data points?
조회 수: 4 (최근 30일)
이전 댓글 표시
I have a data set that is a "double" class 163x1 in a numeric matrix, I would like to spline this data into 100 points instead of 163 data points.
Although I have researched and checked on the 'Help' section of spline, I have followed it to the best of my abilities and I have searched here for answers, unfortunately I have not found my answer.
Furthermore, when I run through this code that I have created it says that "Index in position 2 is larger than array. This should be less than 1".
z = [lCOMz_FS1_1]';
x1 = 0:1:99;
y1 = linspace(z(1,1), z(1,163), 100);
COMz = spline(x1,y1);
plot(x1,y1,COMz)
I'd like to thank anyone in advance for such helping me on such a simple code.
댓글 수: 4
Torsten
2024년 5월 1일
편집: Torsten
2024년 5월 1일
You want to interpolate - thus you have to make your z-data a function of 163 x-values. And in order to interpolate your data in 100 points, you have to specify 100 points somewhere in between these 163 x-values in which you want to do this.
Example:
x = linspace(0,1,163);
f = x.^2;
xinter = linspace(0,1,100);
finter = interp1(x,f,xinter,'spline');
hold on
plot(x,f)
plot(xinter,finter)
hold off
grid on
답변 (2개)
the cyclist
2024년 4월 30일
I expect you want to use the spline method in the interp1 function. It may be possible to give more specific help if you upload the data. (You can attach a MAT file using the paperclip icon from the INSERT section of the toolbar.)
댓글 수: 4
the cyclist
2024년 5월 1일
I didn't see this comment until after Torsten seems to have solved your problem (using interp1!), so I guess you are all set.
Image Analyst
2024년 5월 1일
See attached demo. You can easily use new values for the descriptively-named variables in the demo to do what you want.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Splines에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!