フィルターのクリア

figure not coming up

2 ビュー (過去 30 日間)
taher azim
taher azim 2017 年 3 月 27 日
コメント済み: Image Analyst 2017 年 3 月 28 日
I have written a code in which i have created a rectangular surface using patch command and i m rotating this surface about z axis using the angles i get from my mobile's gyro using udp object.But as irun the code no errors show up but also there is no figure coming up.My code is
instrreset
a=[1 ,-1 ,-1, 1, 1];
b=[1 ,1 ,-1, -1,1];
z=zeros(1,5);
x=zeros(1,5);
y=zeros(1,5);
%Creating UDP object UDPComIn=udp('192.168.173.154','LocalPort',12345); set(UDPComIn,'DatagramTerminateMode','off')
while 1
fopen(UDPComIn);
csvdata=fscanf(UDPComIn);
scandata=textscan(csvdata,'%s %f %f %f %f %f','Delimiter',',');
data=[scandata{4},scandata{5},scandata{6}];
fclose(UDPComIn);
alph=data(1);
for i=1:1:4
t1=[cosd(alph) ,(-sind(alph));sind(alph) ,cosd(alph)];
k=[a(i); b(i)];
m=t1*k;
x(i)=m(1);
y(i)=m(2);
x(5)=x(1);
y(5)=y(1);
end
view(3);
patch(x',y',z');
xlabel('XXX');
ylabel('YYY');
zlabel('ZZZ');
k=k+1;
%CodeEnd
end
but when i run the same patch command while not receiving data from udp just giving angles through for loop it shows no error and figure is also visible.Can anyone plz help me with this problem?
  1 件のコメント
Adam
Adam 2017 年 3 月 27 日
You should create a figure explicitly and refer to the axes explicitly when you create the patch e.g.
hFig = figure; hAxes = axes( hFig );
patch( hAxes, x', y', z' );
It may not be the cause of your problem but it is good practice for making sure you avoid bugs similar to this or have things plotting where you don't expect them.

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

採用された回答

Image Analyst
Image Analyst 2017 年 3 月 27 日
Try putting a
drawnow; % Force refresh/repaint of the screen.
just after you call zlabel().
  2 件のコメント
taher azim
taher azim 2017 年 3 月 28 日
It worked very well thanks but can u give me more insight on drawnow command.
Image Analyst
Image Analyst 2017 年 3 月 28 日
Like the comment says, it forces a repaint of your GUI. If you don't get that, then the message to repaint the GUI window will be sort of deferred until your other compute-intensive stuff finishes. For example if you were in a loop where it computers a new curve and updated a plot 1000 times, then it might wait on updating the plot until the computations were done and then finally get around to updating the display 1000 times, but that would happen so fast that you wouldn't see them all and you just see the final last result. By putting drawnow in there, it forces it to deal with the repainting right then and then, and not put it off to do other stuff in advance.

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

その他の回答 (1 件)

Jan
Jan 2017 年 3 月 27 日
編集済み: Jan 2017 年 3 月 27 日
As far as I understand this must mean, that this code does not finish:
UDPComIn=udp('192.168.173.154','LocalPort',12345);
set(UDPComIn,'DatagramTerminateMode','off')
fopen(UDPComIn);
csvdata=fscanf(UDPComIn);
fclose(UDPComIn);
Did you try to run it outside the loop?
  2 件のコメント
taher azim
taher azim 2017 年 3 月 27 日
I have tried it using outside loop but actually i have to continuously read present angles of my mobile so i have used loop for the same.So if i run it outside loop i get only one value of angles but i have to continuously monitor my mobile angles and present them graphically on screen by rotation of my rectangular block(mobile)
Jan
Jan 2017 年 3 月 27 日
編集済み: Jan 2017 年 3 月 27 日
The current question is, where your code gets stuck. Then the next step will be to find out why.

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

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by