Effacer les filtres
Effacer les filtres

figure not coming up

2 vues (au cours des 30 derniers jours)
taher azim
taher azim le 27 Mar 2017
Commenté : Image Analyst le 28 Mar 2017
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 commentaire
Adam
Adam le 27 Mar 2017
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.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 27 Mar 2017
Try putting a
drawnow; % Force refresh/repaint of the screen.
just after you call zlabel().
  2 commentaires
taher azim
taher azim le 28 Mar 2017
It worked very well thanks but can u give me more insight on drawnow command.
Image Analyst
Image Analyst le 28 Mar 2017
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.

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 27 Mar 2017
Modifié(e) : Jan le 27 Mar 2017
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 commentaires
taher azim
taher azim le 27 Mar 2017
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 le 27 Mar 2017
Modifié(e) : Jan le 27 Mar 2017
The current question is, where your code gets stuck. Then the next step will be to find out why.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by