Filter löschen
Filter löschen

figure not coming up

2 Ansichten (letzte 30 Tage)
taher azim
taher azim am 27 Mär. 2017
Kommentiert: Image Analyst am 28 Mär. 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 Kommentar
Adam
Adam am 27 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jan
Jan am 27 Mär. 2017
Bearbeitet: Jan am 27 Mär. 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 Kommentare
taher azim
taher azim am 27 Mär. 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 am 27 Mär. 2017
Bearbeitet: Jan am 27 Mär. 2017
The current question is, where your code gets stuck. Then the next step will be to find out why.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by