acting on multiple plots across multiple axes

1 visualización (últimos 30 días)
Micah
Micah el 7 de Oct. de 2011
This question might be summed up as: can I create an array or vector where each cell is a plot? but there is almost certainly a better way to do this, so the entirety is below.
I currently have files x1.txt, y1.txt, x2.txt, ... which are only numbers and contain the x and y values of some from different data sets (set 1, set 2, ...) and am plotting them on multiple axes. I have a function that looks like the below:
j=1;
while j <= 14
axes('Position',[.06,.94-(j-1)*.065,.93,.04]);
xdata = load(['../matlabresults/x' num2str(j) '.txt']);
ydata = load(['../matlabresults/y' num2str(j) '.txt']);
bar(xdata, ydata)
end
Which does exactly what I want. I want to manipulate these bar graphs later though (to make them visible and invisible upon user control) but they are not saved to a handle. If I do something like:
mylocation = axes('Position',[.06,.94-(j-1)*.065,.93,.04]);
myplot = bar(xdata, ydata)
Then the handle is overwritten each time, whereas if I do something like:
mylocation{j} = axes('Position',[.06,.94-(j-1)*.065,.93,.04]);
myplot{j} = bar(xdata, ydata)
Matlab complains that I can't write those sort of data to an array. Any advice? Is there a natural handle that each of these plots will take?
Note: Using Matlab2011b on MacOSX Lion. Note also that the actual function involves plotting 10 graphs per axes, along with annotation, but I still only want to manipulate one plot at a time (on all the 14 axes) upon user input, and simplified here for space.

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 7 de Oct. de 2011
The MATLAB complaint is probably caused by your your previous definition of mylocation and myplot. If you initialize them properly, you should not have any problem. mylocation can be declared as double array, instead of cell array.
mylocation=cell(14,1);
myplot=cell(14,1);
mylocation{1} = axes;
mylocation{2} = axes;
mylocation{3} = axes;
myplot{1}=bar(rand(10,5),'stacked');
myplot{2}=bar(rand(10,5),'stacked')
myplot{3}=bar(rand(10,5),'stacked')
  1 comentario
Micah
Micah el 7 de Oct. de 2011
Thanks - that worked perfectly. I was not defining them at all before.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 7 de Oct. de 2011
Beyond what Fangjun said:
mylocation{j} = axes('Position',[.06,.94-(j-1)*.065,.93,.04]);
myplot{j} = bar(mylocation{j},xdata, ydata);
That is, after you create the axes, you want to be sure that your new bar plot draws in that axes.
  1 comentario
Micah
Micah el 7 de Oct. de 2011
yes - I had that in there but forgot to add it when abbreviating the code for this forum. Thanks!

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by