Connect uitable to specific figure

4 Ansichten (letzte 30 Tage)
jakob ekwall
jakob ekwall am 20 Jan. 2016
Kommentiert: Walter Roberson am 20 Jan. 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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 20 Jan. 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 Kommentare
jakob ekwall
jakob ekwall am 20 Jan. 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 am 20 Jan. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by