how make the plot continuous ?

40 ビュー (過去 30 日間)
tomer polsky
tomer polsky 2020 年 1 月 18 日
編集済み: Adam Danz 2020 年 1 月 20 日
So I want to make a plot of PWM ,how ever the plot commant make it wrong becouse it conects the dots in the wrong places . for exmaple , I want to make PWM of 10 Hz when the duty cycle is 60% . so this is the code :
clc;clear all;
vector_ones=ones(1,10);
for i=1:10
if(6<i)
vector_ones(i)=0;
end
end
figure(1);
plot(1:10,vector_ones,'red');
figure(2);
stem(1:10,vector_ones,'red');
as you can see in figure 2 the stem plot 0-6 I get ones and after 7 it all zeors :
and when I use regular plot insted of stem there is diaganole between 6 and 7,the question how can I make it like the stem plot but continuous ?
  1 件のコメント
Adam Danz
Adam Danz 2020 年 1 月 18 日
I'm having trouble visualizing what you're describing. What would the continuous step plot look like?

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

採用された回答

J. Alex Lee
J. Alex Lee 2020 年 1 月 18 日
If I understand correctly, you want the "plot" command to produce a vertical "line" at x=6. To do this, you could duplicate the x-variable at value 6, and make it double-valued in the y variable:
x = [1:6,6:10]
y = ones(size(x))
y(7:end) = 0
figure(3)
plot(x,y,'o-')
Is this what you are looking for?
  2 件のコメント
tomer polsky
tomer polsky 2020 年 1 月 18 日
yes thank you very much
Adam Danz
Adam Danz 2020 年 1 月 18 日
Note that this solution will only work with this exact input vector.

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

その他の回答 (1 件)

Adam Danz
Adam Danz 2020 年 1 月 18 日
編集済み: Adam Danz 2020 年 1 月 20 日
If a step function is what you're looking for, this single line below will calculate the x values for any vector of 1s and 0s.
x = cumsum([0,diff(vector_ones)]==0);
plot(x,vector_ones, 'r-')
ylim([-1 2])
grid on

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by