acting on multiple plots across multiple axes

조회 수: 1 (최근 30일)
Micah
Micah 2011년 10월 7일
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
Micah
Micah 2011년 10월 7일
Thanks - that worked perfectly. I was not defining them at all before.

댓글을 달려면 로그인하십시오.

추가 답변 (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