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