how to plot a sequence over a given interval

Hello,
After hours upon hours of trying to work this out and a couple of questions here I am having no luck.
I need to plot a seqeunce over a given interval, I have gotten to the point where the sequence is there however I can't find a way around 'vectors must be the same length'
Here is my code...
n = -20:12
x = repmat([5,4,3,2,1],3 15)
linespace(n)
plot(n,x)
I would expect a saw tooth wave looking graph but I get the above mentioned error.
What am I doing wrong? I don't have enough time to play about with the code to try to figure this out as I need to submit a report tomorrow by 11pmand after trying to figure this out for two or three days I am out of ideas.
Any help will be greatly appriciated.

4 件のコメント

Image Analyst
Image Analyst 2020 年 11 月 28 日
What is the range of n for just one triangle? How many times do you want to replicate the triangle, and what should be the expected initial and final values of n once the single waveform has been replicated?
Connor Wright
Connor Wright 2020 年 11 月 28 日
Range for n is -20 to 12
number of replications - 5
With initial and final values I honestly am not sure, I would make an ''educated'' guess at -20 for both.
Image Analyst
Image Analyst 2020 年 11 月 28 日
So, n is the x-axis and you want one triangle going from 1 to 5, peaking in the middle, and you want to replicate it 5 more times, for a total of 6 or 198 elements with the final element being n=178?
Connor Wright
Connor Wright 2020 年 11 月 28 日
Yes, as long as that gives me a graph that looks like a saw tooth wave. Its for a Signal Processing lab report based on MATLAB exercises. I can provide the original data from it if that helps.

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

 採用された回答

Roshan Hingnekar
Roshan Hingnekar 2020 年 12 月 1 日

0 投票

In the code mentioned above the length of vector 'n' is 33, the length of vector 'x' is 75, Hence the plot function is giving error.
Use the following code:
n = linspace(-20,12,75);
x = repmat([5,4,3,2,1],3 ,15);
plot(n,x)
xlim([-20 12])
The aboce code should give the saw-tooth output.

1 件のコメント

Connor Wright
Connor Wright 2020 年 12 月 3 日
Thanks for the help, I ended up using
n = linspace(-20,12,length(x))
Whether or not that is the 'correct' way of doing things is another matter.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by