The explanation is not simple - and, of course, not if you are new to MATLAB and its graphics subsystem.
Your code as is, line by line:
axesHandle= findobj(gcf,'Tag','axes1'); x=rand(randi(10+20,1),4); plot(axesHandle, x);
The first line tries to find in the current figure ( gcf , "get current figure") any child with the 'Tag' property set to the string 'axes1' . Think you know that? The second line, of course, generates some random data to build. The third line displays the data in x .
But after plot -call the 'Tag' property is actually reset to '' (empty string), which in turn makes findobj unsuccessful for any subsequent searches for the axis descriptor. The axesHandle variable, therefore, DOES NOT contain the actual descriptor, but instead an empty matrix [] . This will make the default graph different; it interprets the empty matrix as data for the x-axes (the first argument to plot ). This will result in the error you get:
... Error using plot Vectors must be the same lengths. ...
Dan's solution in the comment above is a workaround, but it makes sense to tell plot where to build, especially in graphical interfaces.
Instead, you can add a fourth line:
set(axesHandle,'Tag','axes1');
This will return the 'Tag' property to 'axes1' , and subsequent clicks on the button will also work. And now you can add multiple axis objects. If that is what you want.