acting on multiple plots across multiple axes

1 次查看(过去 30 天)
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.

采纳的回答

Fangjun Jiang
Fangjun Jiang 2011-10-7
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 个)

Walter Roberson
Walter Roberson 2011-10-7
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 个评论
Micah
Micah 2011-10-7
yes - I had that in there but forgot to add it when abbreviating the code for this forum. Thanks!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by