Custom Triangle with up/down slopes , help

2 views (last 30 days)
Hello i want to make a coustom triangle without using the existing function of matlab, which will start lets say at 300 and will end at 518 , reaching his peak at 408 and max amplitude 1. Note that i want each slope (up-slope and down-slope) should be vectors of 256 elements.So my first thought is to compute a vector va of 256 elements, ok i done it with linspace but then i don't know how to continue. Note that it should be 2 vectors one for up-slope(256 elements) and the other down-slope(256 elements) and it should look like this
any advice appreciated and thanks in advance.

Accepted Answer

Geoff Hayes
Geoff Hayes on 7 Apr 2015
Manolis - it seems that you just need two vectors. One for all elements along the x-axis and one for the elements along the y-axis. You could try
numElems = 256;
x = linspace(300,518,2*numElems-1);
y = linspace(0,1,numElems);
y = [y fliplr(y(1:end-1))];
plot(x,y)
Note how we create an array of evenly spaced elements along the x-axis with a length that is one less than 2*256 (we subtract one due to the overlap at the peak of the triangle). We then evenly space the elements from 0 to 1 along the y-axis, and then combine it with itself once appropriately flipped from left to right (see fliplr) and have removed the last element (due to overlap). Finally, we plot the results to get the triangle that we are interested in.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!