Expand one vector based on another
Show older comments
It was really difficult to come up with a proper title for this question and hence, difficult to google as well. Anyways, my problem is like this:
- I have two vectors x and y
- x(1), x(end), y(1) and y(end) never change
- If I add one or more element, a = [x(1), x(end)] to x: how do I expand y accordingly? Is there a built-in function for this?
Some code to illustrate:
y = [1 2];
y = someFunc([1 2 3], y)
y = [1 1.5 2]
y = [1 2];
y = someFunc([1 2.5 3], y)
y = [1 1.75 2]
1 Comment
Martin Rindarøy
on 6 May 2018
Answers (1)
Ameer Hamza
on 6 May 2018
The following function will work for you
function z = someFun(y, y0)
z = y0(1) + (y-min(y))./(max(y)-min(y))*(y0(2)-y0(1));
end
save it in your MATLAB path and call it as follow
y = [1 2];
y = someFun([1 2.5 3], y)
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!