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:
  1. I have two vectors x and y
  2. x(1), x(end), y(1) and y(end) never change
  3. 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

Martin Rindarøy
Martin Rindarøy 2018년 5월 6일
It seems like interp1 actually does exactly what I want. Silly me :)

댓글을 달려면 로그인하십시오.

답변 (1개)

Ameer Hamza
Ameer Hamza 2018년 5월 6일

0 개 추천

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에 대해 자세히 알아보기

질문:

2018년 5월 6일

댓글:

2018년 5월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by