figure not coming up

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by