cannot get the title and xlabel plotted in a while loop

조회 수: 2 (최근 30일)
Mario Christov
Mario Christov 2016년 10월 5일
댓글: Mario Christov 2016년 10월 5일
Hello, I am using the following code to update the vertical positions on a figure plot of a target marker(p1), joystick marker(p2), and a connecting line between both(p3). I would like to also display the time as title and the position coordinates as xlabel. It worked last week, I don't remember what I changed/deleted since then, but I can't fix it now/ realize what the issue is ? Any suggestions ? Thanks in advance !
k = 1;
while k <= 1000
Y = -(axis(joy, 2));
set(p1,'YData',y1_shifted_abs(k));
set(p2,'YData',Y);
set(p3,'YData',[y1_shifted_abs(k) Y])
time = datestr(now);
title(strcat('Clock time: ',time(end-7:end)));
xlabel({strcat('Target position: ',' ',num2str(y1_shifted_abs(k)));strcat('Joystick position: ',' ',num2str(Y));strcat('\bf Gap: ',' ',num2str(abs(y1_shifted_abs(k) - Y)))});
drawnow
k = k + 1;
end

답변 (2개)

Pritesh Shah
Pritesh Shah 2016년 10월 5일
Give error message.
Y = -(axis(joy, 2)); it should be,
Y = -(axis([joy, 2]));
  댓글 수: 2
Jan
Jan 2016년 10월 5일
Perhaps "axis" is an array?
Mario Christov
Mario Christov 2016년 10월 5일
Writing "Y = -(axis(joy, 2));" is correct. It does not produce an error. It is the correct way of getting the value along the second axis as stated in the documentation

댓글을 달려면 로그인하십시오.


Jan
Jan 2016년 10월 5일
Do you get an error message? Do the results differ from your expectation? Please mention the problem you have.
I think this is nicer:
xlabel({sprintf('Target position: %g', y1_shifted_abs(k)); ...
sprintf('Joystick position: %g', Y); ...
sprintf('\bf Gap: %g', abs(y1_shifted_abs(k) - Y))});
but I do not see a connection to a problem.
  댓글 수: 1
Mario Christov
Mario Christov 2016년 10월 5일
No error messages are returned. The while-loop works well, the marker moves as expected and the joystick too. It's just that the title and xlabel do not get displayed. I tried to execute the commands on the figure after the loop is finished and it still does not work; if I try on another figure plot, it does work => hence it's something with the plot that I cannot figure out what. Before starting the while-loop I create the figure with the following script:
figure
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
axis([-1 1 0 1]);
set(gca,'visible','off'); % hide all axes lines
hold on
line([-0.1 -0.1],[0 1],'LineWidth',4); % line([x1 x2],[y1,y2])
line([0.1 0.1],[0 1],'LineWidth',4);
p1 = plot(-0.1,0.5, 'o','MarkerFaceColor','w','MarkerSize',18,'MarkerEdgeColor','k'); % TARGET MARKER
p2 = plot(0.1,0.5,'o','MarkerSize',18,'MarkerEdgeColor','w','MarkerFaceColor','k'); % JOYSTICk MARKER
p3 = line([-0.1 0.1],[0.5,0.5],'LineWidth',3,'LineStyle',':','Color',[0 0 0]); % CONNECTING LINE, black
hold off
set(p1,'XData',-0.1);
set(p2,'XData',0.1);
set(p3,'XData',[-0.1 0.1])

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by