Question

I am trying to adjust the heights of a boxplot. Simple example:

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;  % adjust height
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

Was it helpful?

Solution

It turns out that h is an array of handles, since there are multiple objects in this figure.

Thus, the manipulations must be performed in each entry in the array h separately.

e.g.

ydata = get(h(1), 'YData');
% do stuff to ydata,
set(h(1), 'YData', ydata);

ydata = get(h(2), 'YData');
% do stuff to ydata,
set(h(2), 'YData', ydata);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top