Problem after interp1.

A matrix has a lot of 151 and 1 values.
A = [ 1 1.5 2 2.33 2.67 3 ....... 150.75 151 101 51 1 1.5 2 2.33 2.67 3 3.33 ......]
problem after 151, i'd like to change 101 51 to 0.33 0.67 by considering 151 as 0.
B=find(A(1,:)==151); % call the column numbers of 151
C=find(A(1,:)==1); % call the column numbers of 1
Data: 1) The column number of 151 and 1.
2) The number of columns between 151 and 1 can be known
by D=B(i,1)-C(i+1,1);
Is there any way to implement linear interpolation from 151 to 1 with considering 151 as 0?

2 件のコメント

Jan
Jan 2015 年 11 月 18 日
Do you mean:
B = find(A(1,:) == 151)
?
Hyowon Lee
Hyowon Lee 2015 年 11 月 18 日
Yes, I'm sorry about that. I revised the part.

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 11 月 18 日

0 投票

Passing 151 as the second parameter to find() means that you want to find the 151st location that is not equal to 0. To find locations that are equal to 151 you need to be comparing to 151 in your first parameter to the call.
find(x==151)
Chad Greene
Chad Greene 2015 年 11 月 18 日

0 投票

Try this:
A = [1 1.5 2 2.33 2.67 3 150.75 151 101 51 1 1.5 2 2.33 2.67 3 3.33];
% A has these corresponding x values:
startingLength = length(A);
x = 1:startingLength;
% Get all the 151s in A:
ind = find(A==151);
% Set 151s to zero:
A(ind) = 0;
% Delete the next two entries in A after each occurence of 151:
A(ind+1:ind+2) = [];
x(ind+1:ind+2) = [];
% Create a new A by interpolating to all the starting indices:
A = interp1(x,A,1:startingLength)

この質問は閉じられています。

質問済み:

2015 年 11 月 18 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by