Custom Triangle with up/down slopes , help

2 ビュー (過去 30 日間)
Manolis Michailidis
Manolis Michailidis 2015 年 4 月 7 日
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.

採用された回答

Geoff Hayes
Geoff Hayes 2015 年 4 月 7 日
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.
  1 件のコメント
Manolis Michailidis
Manolis Michailidis 2015 年 4 月 7 日
thanks works like a charm

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by