필터 지우기
필터 지우기

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 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