Info

This question is closed. Reopen it to edit or answer.

Problem after interp1.

1 view (last 30 days)
Hyowon Lee
Hyowon Lee on 18 Nov 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
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 Comments
Jan
Jan on 18 Nov 2015
Do you mean:
B = find(A(1,:) == 151)
?
Hyowon Lee
Hyowon Lee on 18 Nov 2015
Yes, I'm sorry about that. I revised the part.

Answers (2)

Walter Roberson
Walter Roberson on 18 Nov 2015
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 on 18 Nov 2015
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)

Community Treasure Hunt

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

Start Hunting!