Hello,
I have a report due in two days and have no idea how to plot this sequence. I know almost nothing about Matlab and my tutors as usual have been no help at all.
If some one can help me out here I would greatly appriciate it.
The sequence is:
๐‘ฅ(๐‘›) = {โ€ฆ , 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, โ€ฆ }
Cheers

๋Œ“๊ธ€ ์ˆ˜: 2

Mario van Rooij
Mario van Rooij 2020๋…„ 11์›” 27์ผ
Where does the n come into play? What do you want to plot when n = 10 for example?
Connor Wright
Connor Wright 2020๋…„ 11์›” 27์ผ
I want to plot โˆ’20 โ‰ค ๐‘› โ‰ค 12.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

 ์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Star Strider
Star Strider 2020๋…„ 11์›” 27์ผ

0 ๊ฐœ ์ถ”์ฒœ

The mod function and the colon,: operator are your friends!

๋Œ“๊ธ€ ์ˆ˜: 6

Connor Wright
Connor Wright 2020๋…„ 11์›” 27์ผ
How would I implement the mod function?
Star Strider
Star Strider 2020๋…„ 11์›” 27์ผ
Example โ€”
x = 0:30;
y = mod(x, 15);
figure
plot(x, y)
grid
I leave the rest to you!
Connor Wright
Connor Wright 2020๋…„ 11์›” 27์ผ
Right first off thank you for putting me on the right path, however I have staryed off it and went down a different route and have run into trouble. my code is below and I keep getting the sam error of 'error using plot vectors must be the same length'
n = -20:12
x = repmat([5,4,3,2,1],3,15)
linspace = x
plot(n,x)
Error using plot
Vectors must be the same length
Any ideas?
Star Strider
Star Strider 2020๋…„ 11์›” 27์ผ
Use the colon operator with the โ€˜nโ€™ vector, and then operate on it to create the triangular pulses.
That will eliminate the vector length problem.
Connor Wright
Connor Wright 2020๋…„ 11์›” 27์ผ
I really am sorry about this but I dont understand what you mean.
Star Strider
Star Strider 2020๋…„ 11์›” 27์ผ
Please experiment!
Use my example as a guide, and carefully read the documentation for colon. Note how to use it to code a descending sequence.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ถ”๊ฐ€ ๋‹ต๋ณ€ (0๊ฐœ)

์นดํ…Œ๊ณ ๋ฆฌ

๋„์›€๋ง ์„ผํ„ฐ ๋ฐ File Exchange์—์„œ Loops and Conditional Statements์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

์ œํ’ˆ

๋ฆด๋ฆฌ์Šค

R2020b

ํƒœ๊ทธ

์งˆ๋ฌธ:

2020๋…„ 11์›” 27์ผ

๋Œ“๊ธ€:

2020๋…„ 11์›” 27์ผ

Community Treasure Hunt

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

Start Hunting!

Translated by