It seems that PLOT command is being bypass and not being execute..

delete(instrfindall)
clear all;clc
s = serial('COM6');
fopen(s)
A1 = 0; B1 = 0;
for i = 1:1000
P = fscanf(s,'%f')
if P == 1
A1 = A1+1; B1 = B1;
elseif P == 2
A1 = A1-1; B1 = B1;
elseif P == 3
A1 = A1; B1 = B1+1;
elseif P == 4
A1 = A1; B1 = B1-1;
else
end
plot(A1,B1,'*')
hold on
end
fclose(s)
delete(instrfindall)
I have written this code. I am receiving serially data very wel . But plot command is not being executed. As well * is not moving accordingly. Please correct me.

 採用された回答

Image Analyst
Image Analyst 2016 年 5 月 14 日

0 投票

A1 and B1 are just points, not vectors or arrays. So you will just see a single point, not a curve. To see it better, try this:
plot(A1, B1, 'b*', 'LineWidth', 2, 'MarkerSize', 30);
grid on;
If you want more points, then you need to make A1 and B1 vectors, or else put "hold on" and call plot over and over again with new values of A1 and B1.

6 件のコメント

Nimisha
Nimisha 2016 年 5 月 14 日
I didn't want curve. I just want only single point.
But actual problem is that in my written code plot command is being bypass.
I am receiving continuous data from microcontroller serially. But its effect is not displayed on plot.
Image Analyst
Image Analyst 2016 年 5 月 14 日
So use the debugger. Put a break point early in the code and see where the code steps to, and then you'll discover why it's never getting to the plot() call. If you don't know how to use the debugger, see this: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
Nimisha
Nimisha 2016 年 5 月 15 日
I run it step by step and it works fine. No problem.
But when I run it in continuous mode plot is not being generated. It seems that plot command is being bypass.
Image Analyst
Image Analyst 2016 年 5 月 15 日
Put in a drawnow
drawnow;
You might also put in a pause(0.5) if you want more time to view it.
Walter Roberson
Walter Roberson 2016 年 5 月 15 日
Good point about the drawnow()
Nimisha
Nimisha 2016 年 5 月 16 日
編集済み: Nimisha 2016 年 5 月 16 日
Thanks.
drawnow
Commmand works well to show and update plot.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 5 月 14 日

0 投票

After the
hold on
add
set(gca, 'xlimmode', 'auto', 'ylimmode', 'auto')

1 件のコメント

Nimisha
Nimisha 2016 年 5 月 15 日
Ya. Thanks I modified my code with this command.
But my actual problem is mentioned above.

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

カテゴリ

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

質問済み:

2016 年 5 月 14 日

編集済み:

2016 年 5 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by