set graphics object ydata which is a cell

I am trying to adjust the heights of a boxplot.
boxplot(1:10,[zeros(1,5) ones(1,5)], 'colorgroup', [0 1], 'colors', 'rb', 'orientation', 'horizontal')
h = findobj(gcf, 'tag', 'Box');
ydata = get(h, 'YData');
celldisp(ydata);
ydata{1} = ydata{1}*0.60;
set(h, 'YData', ydata);
Note that celldisp(ydata) displays:
ydata{1} =
1.8500 1.8500 2.1500 2.1500 1.8500
ydata{2} =
0.8500 0.8500 1.1500 1.1500 0.8500
And the above code gives the error:
Error using set
Conversion to double from cell is not possible.
How do I set 'YData', as it is a cell?
Please note, this is a simplified extraction from much more complicated code. In general, the elements of the cell ydata are NOT all the same length, hence you cannot just use cell2mat or something on ydata

 採用された回答

Sean de Wolski
Sean de Wolski 2014 年 3 月 10 日

2 投票

If you look at h it's actually a 1x2 vector of handles. Thus you're getting the ydata from two separate handles and you'll need to change it for each individually. Simplest way is to use a for-loop
boxplot(1:10,[zeros(1,5) ones(1,5)], 'colorgroup', [0 1], 'colors', 'rb', 'orientation', 'horizontal')
h = findobj(gcf, 'tag', 'Box');
ydata = get(h, 'YData');
for ii = 1:numel(h)
set(h(ii),'YData',ydata{ii});
end

1 件のコメント

Matthew
Matthew 2014 年 3 月 10 日
編集済み: Matthew 2014 年 3 月 10 日
I didn't think to check the dimensions of h ! That works very well. Thank you so much!!!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

質問済み:

2014 年 3 月 10 日

編集済み:

2014 年 3 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by