Question

Hi Im a matlab beginner. Would you plz solve my problem? Thanks! Matlab) How to make a code about...

Hi Im a matlab beginner. Would you plz solve my problem? Thanks!
Matlab)
How to make a code about interpolation?(without using interp1,imresize..etc the internal function)

I=[1 10 25 432 28 294 70 80]
How to make the I2 whose length is 11 with linear interpolation?(Without matlab function such as imresize!!)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Explanation : I have sorted the data points. I am finding out the points which are more required. I am using the line equation y = mx + c to find new point between two points.
I have taken the given points as value on y-axis and for x-axis I have considered their position values (1 to number of elements).
so to find out any new point I have used y = y1 + slope*(x - x1)
where y1 is the first point and x1 is its position, slope is (y2-y1)/(x2 - x1)
x2, x1 are the position of points y2, y1.
Below is the function which I have implemented for linear interpolation:
I have considered that len(required length) will be more than or equal to the size of given data points.


function res = linearinterpolation(input,len)
% input is the provided set of points
% len is the required length
inputsize = numel(input);
res = [];
if inputsize == len
res = input;
return;
end
sorteddata = sort(input);
diff = len - inputsize;
%diff has the number of new points required to make.
newpoints = [];
%newpoints vector will be having the new points.
for i = 1 : diff
y1 = sorteddata(i);
y2 = sorteddata(i+1);
x1 = i;
x2 = i+1;
slope = (y2 - y1)/(x2 - x1);
xnew = (i + i+1)/2;
val = y1 + slope * (xnew - x1);
   %using the line equation y = mx + c, more explanation is above
newpoints = [ newpoints , val];
  
end
res = [input , newpoints];


end

Add a comment
Know the answer?
Add Answer to:
Hi Im a matlab beginner. Would you plz solve my problem? Thanks! Matlab) How to make a code about...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT