Hello,
I want to plot a set of binary values such that each binary value will be shown for 50 seconds. I tried like this but was unable to get the pulse signal of binary values(0 and 1). binary =[1 1 0 1 0 0 1 0];assume this is my binary data
for l=1:1:length(binary)
for t=i:1:i+50
plot(t,binary(l),'-r');
ylim([-2 2]);
end
i=i+1;
end
can someone suggest in plotting this binary data(as I want to plot the data in real time).
Thank you.

1 件のコメント

Henric Rydén
Henric Rydén 2014 年 6 月 2 日
i is not defined

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

 採用された回答

Henric Rydén
Henric Rydén 2014 年 6 月 2 日

0 投票

If you want to show each value in binary for 50 seconds
binary =[1 1 0 1 0 0 1 0];
figure;
for idx = 1 : length(binary)
stem(0,binary(idx));
xlim([-1 1]);
ylim([0 1.5]);
title(['Binary (' num2str(idx) ')']);
drawnow;
pause(50);
end

4 件のコメント

Gova ReDDy
Gova ReDDy 2014 年 6 月 2 日
Sorry, if I didn't explained it correctly.Here, I am explaining again clearly of what I am interested to do.
Matlab will be receiving characters through serial port.Each time the received character has to be converted to integer and then to binary and plotted them.
The plot should show all the 8bits of the converted binary data such that the each binary bit should be shown for 50ms and then the next bit for the next consecuitve 50ms and so on untill the end of 8bit data. When a new data is received it the plot should be showing the newly obtained 8bit data where the time axis should be continuous(followed with ) to the last time value.
Henric Rydén
Henric Rydén 2014 年 6 月 2 日
I'm not sure if I understand correctly, I think you are mixing bytes with bits . Assuming you want to show the latest byte in a continously growing vector for 50 ms:
binary =[1 1 0 1 0 0 1 0];
figure;
acquiring = true;
while acquiring
stem(1:8,binary(end-7:end));
xlim([0.5 8.5]);
ylim([0 1.5]);
title(['Latest byte of data']);
drawnow;
pause(.05);
end
As I don't have the code for acquiring the data,I assume that you are simply appending binary. You should adjust the while statement to trigger on new acquisitions.
Gova ReDDy
Gova ReDDy 2014 年 6 月 2 日
Thanks.Can I know how to show the binary plot as square pulse as shown in the below figure instead of stem representation.
Henric Rydén
Henric Rydén 2014 年 6 月 2 日
Sure! There are many ways to do this, but replace stem with bar and you're halfway there:
bar(1:8,binary(end-7:end),'BarWidth',1);
If you want something more similar to what you've drawn, you should use line . But you should center the pulses over the values to avoid confusion.
stem is a more correct way to represent the data, since values are not defined between integers.

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

その他の回答 (0 件)

カテゴリ

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

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by