Issue with updating xlabel/ylabel
8 views (last 30 days)
Hi all. I have what may be a somewhat odd question. I have a GUI that I use for data analysis. In that GUI is a uipanel with a set of axes automatically created (actually, there are multiple panels and axes, only one is visible/active at a time). I also have in the axes a context menu that allows the user to apply scaling/offset parameters to the plotted data (i.e. you can offset all the x-axis data by 100 and it will add 100 to the xdata array of all the lines, etc). This all works fine.
When a user uses either of these context menu options, I also want to update the xlabel and ylabel to reflect the change. I have done this by a function that updates the xlabel or ylabel on demand doing something like this:
xtitle = get(get(curr_axes,'xlabel'),'String'));
xoffset = 'Some String from inputdlg';
xlabel(curr_axes,[xtitle,' + [',xoffset,']']);
Again, this actually works fine as well - everything is updated and looks great. Everything is on one line and oriented properly. It looks something like this, all on one line:
Original X Title + [offset]
The issue comes when I try to update an xlabel or ylabel that has already been updated. For example, I also have a context menu item that allows the user to manually change the xlabel and ylabel strings. If the user does this, when they go to apply an offset or scalar, the (x/y)label becomes a fixed width and some weird word wrap takes place. It then looks something like this:
And now the xlabel takes up four lines instead of one, and there's only a few characters on each line.
The code I'm using to update the label manually (not append it) is basically the same as the above code, except I just pass a normal string to the xlabel command instead of a concatenated string. I also tried deleting the old one to see if that was causing any issues with parameters being held over (like 'OuterPosition' or 'Units,' etc), but that does not seem to have resolved it either.
AJ von Alt on 21 Jan 2014
Edited: AJ von Alt on 21 Jan 2014
Check if the xlabel string is a cell array when you retrieve it.
If it is a cell, then the code:
xoffset = blah;
xtitle = get( get( gca , 'xlabel' ) , 'string' );
stringToWrite = [xtitle,' + [',xoffset,']']
set( get(gca , 'xlabel') ,'string' ,stringToWrite )
will add xtitle , ' + [' , xoffset and ']' as elements of the cell array stringToWrite. When the 'string' property of xlabel is set to a cell array, each element of the cell array is printed on a separate line. This would explain why your labels appear to be wrapping.