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.
댓글 수: 0
채택된 답변
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!