how can i avoid return to zero from my plot

7 visualizaciones (últimos 30 días)
Mohamed Essam
Mohamed Essam el 24 de Mzo. de 2019
Comentada: Mohamed Essam el 24 de Mzo. de 2019
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) ']']);

Respuesta aceptada

Kodavati Mahendra
Kodavati Mahendra el 24 de Mzo. de 2019
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 comentarios
Kodavati Mahendra
Kodavati Mahendra el 24 de Mzo. de 2019
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 el 24 de Mzo. de 2019
thank you very much

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by