how can i avoid return to zero from my plot

7 ビュー (過去 30 日間)
Mohamed Essam
Mohamed Essam 2019 年 3 月 24 日
コメント済み: Mohamed Essam 2019 年 3 月 24 日
Bitsnum = 11;
dataIn = randi([0 1],1,Bitsnum);
i = 1;
count = 0;
t = 0:.01:length(dataIn);
for j =1:length(t)
if t(j) >= (0+count) && t(j) <= (0.5+count);
if dataIn(i) == 1;
manchester(j) = 2;
elseif dataIn(i) == 0;
manchester(j) = -2;
end
elseif t(j) > (.5+count) && t(j) <= (i);
if dataIn(i) == 1;
manchester(j) = -2;
elseif dataIn(i) == 0;
manchester(j) = 2;
end
else
i = i+1;
count = count+1;
end
end
subplot(3,2,5);
plot(t,manchester,'LineWidth',2,'color','red');
axis([0 length(dataIn) -3 3])
grid on;
title(['manchester: [' num2str(dataIn) ']']);

採用された回答

Kodavati Mahendra
Kodavati Mahendra 2019 年 3 月 24 日
Bitsnum = 11;
dataIn = randi([0 1],1,Bitsnum);
i = 1;
count = 0;
t = 0:.01:length(dataIn);
for j =1:length(t)
if t(j) >= (0+count) && t(j) <= (0.5+count);
if dataIn(i) == 1;
manchester(j) = 2;
elseif dataIn(i) == 0;
manchester(j) = -2;
end
elseif t(j) > (0.5+count) && t(j) <= (i);
if dataIn(i) == 1;
manchester(j) = -2;
elseif dataIn(i) == 0;
manchester(j) = 2;
end
else
manchester(j)= manchester(j-1);
i = i+1;
count = count+1;
end
end
% subplot(3,2,5);
plot(t,manchester,'LineWidth',2,'color','red');
axis([0 length(dataIn) -3 3])
grid on;
title(['manchester: [' num2str(dataIn) ']']);
I am not sure if i understand your question properly. Does this code solve your problem?
The problem is with your ifelse loop. for some j, manchester(j) is undefined. MATLAB assigned it a default value of 0. So I added one more line inside else. Does this work?
  2 件のコメント
Kodavati Mahendra
Kodavati Mahendra 2019 年 3 月 24 日
for example, check the output of the following command to understand the problem with your code.
x(1) = 1;
x(10) = 1;
plot(x);
MATLAB doesn't know the values of x(2) to x(9). So it sets them to 0 and plots the graph. If you want them to be something different, you should declare them properly.
Maybe
x(1:10) = 1;plot(x);
Mohamed Essam
Mohamed Essam 2019 年 3 月 24 日
thank you very much

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by