Issue with updating xlabel/ylabel
5 ビュー (過去 30 日間)
古いコメントを表示
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';
delete(get(curr_axes),'xlabel'));
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:
X Title
+ [
xoffset
]
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.
Any ideas?
2 件のコメント
採用された回答
AJ von Alt
2014 年 1 月 21 日
編集済み: AJ von Alt
2014 年 1 月 21 日
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.
その他の回答 (1 件)
Doug Hull
2014 年 1 月 20 日
Can you save the handle of the updated label, and just change the string property?
3 件のコメント
Walter Roberson
2014 年 1 月 21 日
The xlabel() and ylabel() calls set the axis XLabel and YLabel properties to the handles of text objects. So
set( get(gca,'XLabel'), 'String', 'Some New String')
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!