How to shift the matrix values by a specified function?
Show older comments
I'm trying to shift the values of a matrix R ('a simple road with heigthened borders') by a function yy ('a curve') in order to turn the straight road into a curved road. Please look at the picture and code below for better understanding. Is there a way to achieve this? I'm at my wits end. Thank you in advance!

% matrix
xlim = 0:0.5:20;
ylim = -10:0.125:10;
[xr,yr]= meshgrid(xlim,ylim);
r = zeros(length(ylim), length(xlim));
ylim2 = -5:0.125:5;
[x,y]= meshgrid(xlim,ylim2);
r1 = (1./(y-5)).^2 ;
r2 = (1./(y+5)).^2;
r12 = max(r1,r2);
n = (length(ylim)-length(ylim2))/2;
r(n:n+length(ylim2)-1, 1:length(xlim)) = r12;
figure
surf(xr,yr,r)
title('R')
% function
xp = [0 10 20];
yp = [0 1 5];
yy = pchip(xp,yp,xlim);
figure
plot(xp,yp,'o',xlim,yy)
title('yy')
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!


