필터 지우기
필터 지우기

Connect uitable to specific figure

조회 수: 2 (최근 30일)
jakob ekwall
jakob ekwall 2016년 1월 20일
댓글: Walter Roberson 2016년 1월 20일
So I've added a uitable to a figure in order to be able to distinguish the min and max value for a certain time span. By looking at the plot the user can approximately tell at what time the min & max should occur, in order to be find actual min & max one has to study the table since it is hard to distinguish these from looking only at the plot. The use then enters at what time the min & max occur in a input dialogue. There is probably a much more efficient way to do this but this works fine.
The problem is however the uitable. I thought it would be connected only to the figure mentioned above, however when i plotted other results obtained later in the code the uitable showed up in this figure as well.
Here is the code:
figure('position',[0,0,1440,990])
plot(xtim,v_timav,'black',xtim,h_timav,'r');
set(gca,'Xtick',xtim,'XTickLabelRotation',45,'Xgrid','on','ylim',[0 65]);
datetick('x','HH:MM');
title('Normalday','Fontsize',16,'Fontweight','normal')
xlabel('[ h ]','Fontsize',14,'Color',[0.5 0.5 0.5]);
ylabel('[ l/s ]','Fontsize',14,'Color',[0.5 0.5 0.5]);
le2=legend('Veckodag','Helgdag','Location','northeast');
set(le2,'Fontsize',12);
cnames = {'Veckodag','Helgdag'};
rnames = {'00:00','01:00','02:00','03:00','04:00','05:00','06:00','07:00','08:00','09:00','10:00','11:00','12:00','13:00','14:00','15:00'...
'16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00'};
uitable('Position',[205,370,230,360],'Data',averageday,'ColumnName',cnames,'RowName',rnames)
How do I make it stay out of my other figures?

채택된 답변

Walter Roberson
Walter Roberson 2016년 1월 20일
fig = figure('position',[0,0,1440,990]);
ax = axes('Parent', fig);
ph = plot(ax, xtim,v_timav,'black',xtim,h_timav,'r');
set(ax'Xtick',xtim,'XTickLabelRotation',45,'Xgrid','on','ylim',[0 65]);
datetick(ax, 'x','HH:MM');
title(ax, 'Normalday','Fontsize',16,'Fontweight','normal')
xlabel(ax, '[ h ]','Fontsize',14,'Color',[0.5 0.5 0.5]);
ylabel(ax, '[ l/s ]','Fontsize',14,'Color',[0.5 0.5 0.5]);
le2 = legend(ax, ph, 'Veckodag','Helgdag','Location','northeast');
set(le2,'Fontsize',12);
cnames = {'Veckodag','Helgdag'};
rnames = {'00:00','01:00','02:00','03:00','04:00','05:00','06:00','07:00','08:00','09:00','10:00','11:00','12:00','13:00','14:00','15:00'...
'16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00'};
uitable('Parent', fig, 'Position',[205,370,230,360],'Data',averageday,'ColumnName',cnames,'RowName',rnames)
Now all the graphics are certain to go to the right place.
  댓글 수: 2
jakob ekwall
jakob ekwall 2016년 1월 20일
Thanks!
What exactly did I do wrong? Just for future reference, if I run in to the same problem again..
Walter Roberson
Walter Roberson 2016년 1월 20일
With the code you had, if you accidentally click a different figure while this code is running, then the uitable would get attached to the other figure. That includes if you drop into the debugger and move a window to be able to see what you are doing, and also includes if a callback happened that updated a different figure or if you called a function that updated a different figure. With the code I give here, you can click or debug or call functions all you like and the graphics would still go to the right place.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by