Expand one vector based on another
显示 更早的评论
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 个)
Ameer Hamza
2018-5-6
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)
类别
在 帮助中心 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!