How to completely change the title of a plot when switching between two cases?
Show older comments
Good morning! I have a problem with a GUI in Matlab. I have a plot, in the main window of the GUI, which is updated when switching from one case to the other of a "switch" button. Everything is actually updated but the title: when I switch to the second case, it is overwritten. I tried to use the "drawnow" command, the "refresh", also "refreshdata", but none of them works (all have left traces in the code...). The faulty code is:
-----------------------------------------------------
switch DataOpt
case 1
fig = gcbf;
refresh(fig);
ax1 = gca;
set(ax1,'XLim',[Data.lambda(1),Data.lambda(end)]);
set(ax1,'XColor','k','YColor','k');
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k','YColor','k');
set(ax2,'YTickLabel','');
set(ax2,'XLim',[1,400]);
set(ax2,'YLim',[min(Data.data(FixedDelay,:)),max(Data.data(FixedDelay,:))]);
set(ax1,'YLim',[min(Data.data(FixedDelay,:)),max(Data.data(FixedDelay,:))]);
XLim1=get(ax1,'XLim');
xinc1=(XLim1(2)-XLim1(1))/5;
YLim1=get(ax1,'YLim');
yinc1=(YLim1(2)-YLim1(1))/5;
set(ax1,'XTick',[XLim1(1):xinc1:XLim1(2)],...
'YTick',[YLim1(1):yinc1:YLim1(2)]);
hl1 = line(Data.lambda,Data.data(FixedDelay,:),'Color','b','Parent',ax1);
xlabel(ax2,'# pixel');
xlabel(ax1,'\lambda (nm)');
ylabel(ax1,'Fluorescence');
title(['Spectrum, delay = ' num2str(Data.delays(FixedDelay)) ' ns, raw']'');
case 2
drawnow update;
fig = gcbf;
refresh(fig);
%refreshdata;
ax1 = gca;
set(ax1,'XLim',[Data.lambda(1),Data.lambda(end)]);
set(ax1,'XColor','k','YColor','k');
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k','YColor','k');
set(ax2,'YTickLabel','');
set(ax2,'XLim',[1,400]);
set(ax2,'YLim',[0,1]);
set(ax1,'YLim',[0,1]);
XLim1=get(ax1,'XLim');
xinc1=(XLim1(2)-XLim1(1))/5;
YLim1=get(ax1,'YLim');
yinc1=(YLim1(2)-YLim1(1))/5;
set(ax1,'XTick',[XLim1(1):xinc1:XLim1(2)],...
'YTick',[YLim1(1):yinc1:YLim1(2)]);
hl1 = line(Data.lambda,Data.dataNorm(FixedDelay,:),'Color','b','Parent',ax1);
xlabel(ax2,'# pixel');
xlabel(ax1,'\lambda (nm)');
ylabel(ax1,'Fluorescence');
title(['Spectrum, delay = ' num2str(Data.delays(FixedDelay)) ' ns, normalized']'');
end
------------------------------------------------------------------------------------
Has anybody idea of what do I err?
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!