Connect uitable to specific figure

1 visualización (últimos 30 días)
jakob ekwall
jakob ekwall el 20 de En. de 2016
Comentada: Walter Roberson el 20 de En. de 2016
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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de En. de 2016
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 comentarios
jakob ekwall
jakob ekwall el 20 de En. de 2016
Thanks!
What exactly did I do wrong? Just for future reference, if I run in to the same problem again..
Walter Roberson
Walter Roberson el 20 de En. de 2016
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by