Error in Using interp1

조회 수: 4 (최근 30일)
ugurcan sahin
ugurcan sahin 2016년 5월 29일
답변: Image Analyst 2016년 5월 30일
Hello everyone i have an array named 'x' and trying to interpolate it but i am getting an error as "Interpolation requires at least two sample points in each dimension." Here is my code;
x_1 = interp1(0:duration*44100,X,0:1:duration*44100,'linear');
I need to resize x array to (duration * 44100). Any help would be great. Thanks.
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2016년 5월 29일
ugurcan - what can you tell us about duration and X? It would be interesting to know what duration is so that we can determine the range of
0:duration*44100
and how many elements are in X.
ugurcan sahin
ugurcan sahin 2016년 5월 29일
편집: Walter Roberson 2016년 5월 29일
duration is an input which is max 10, for x it is better to show my code
function generate_sound(sigma, rho, beta, vector, duration)
[duration,newvector] = ode45(@lor2,[0,10*duration],vector);
x_0 = newvector(:,1);
y_0 = newvector(:,2);
z_0 = newvector(:,3);
function empty = lor2(duration,vector)
empty = zeros(3,1);
empty(1) = -sigma*vector(1) + sigma*vector(2);
empty(2) = rho*vector(1) - vector(2) - vector(1)*vector(3);
empty(3) = -beta*vector(3) + vector(1)*vector(2);
end
X = x_0;

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2016년 5월 29일
That code does not show an interp1 ?
If the duration being interpolated over is the output of the ode45 call, then note that it is a vector, not a scalar.
Your X is going to be a column vector: it could make a difference to interp1 to transpose it to be a row vector.

Image Analyst
Image Analyst 2016년 5월 30일
You vectors are wrong, especially the first arg to interp1(). This works:
duration = 2;
X = audioread('guitartune.wav'); % Read sample data.
% Define how you want to resample it
resamplingVector = 1 : (duration * 44100);
% Now to the interpolation.
x_1 = interp1(1:length(X), X, resamplingVector,'linear');

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by