Changing title, line color, weight etc in errorbar figures
조회 수: 21 (최근 30일)
이전 댓글 표시
Good day to all,
I have a 152x5 matrix called Seg (Figure 1).
My goal was to graph each row separately which I was able to achieve (Figure 2) with some success [I would have like for each row to have been a different color] using the following code
% code
plot(Seg(1:3,:).','--or','LineWidth',3,'MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',10);
title('Frontal (Fp1,Fp2,F3) Activity over Segments')
xlabel('Segments')
ylabel('Microvolts')
legend('Fp1','Fp2','F3')
legend('Location','Northeast') %move legend to the upper left quadrant
end
I wanted Figure 2 but with error bars to all of these series in such a way that Row 1,2 and 3 of Seg [as seen in Figure 1] each had their respective Standard Error of the Mean (SEM). To the best of my knowledge the only way to achieve this is to use errorbar [please correct me if I'm wrong]. In order to accomplish this I computed the SEM using the following code
% code
%Calculate the standard error of the mean for every row in Seg
SEM_Seg=std(Seg,[],2)/sqrt(length(Seg));
end
Which created a 152x1 matrix. However in order to get errorbar [If not you get the error "Error using errorbar (line 77). X, Y and error bars must all be the same length to work"] I had to copy/paste the 1st column 5 times, the total number of columns in Seg. (Figure 3)
If I use the following code I get the graph seen in Figure 4
% code
errorbar(Seg(1:3,:),SEM_Seg(1:3,:));
end
The problem is that I want to be able to add axis labels, Chart Title, Change line color etc. How is it possible to change these Plot properties? I am able to do so when I use the plot(x) function but this same syntax does not function using errorbar. Perhaps there is an alternative.
I appreciate any criticism, opinions and/or help.
Thanks!
댓글 수: 0
답변 (2개)
Robert Cumming
2014년 7월 25일
편집: Robert Cumming
2014년 7월 25일
is the xlabel etc going on the wrong plot?
if so pass in the axes handle:
xlabel ( axH, 'x label' )
ylabel ( axH, 'y label' )
legend ( axH, 'my legend' )
edit
where axH is the handle to the axes you want to label.
e.g. create 4 figures
f1 = figure;
ax1 = axes ( 'parent', f1 );
plot ( ax1, rand(10), rand(10) );
f2 = figure;
ax2 = axes ( 'parent', f2 );
plot ( ax2, rand(10), rand(10) );
f3 = figure;
ax3 = axes ( 'parent', f3 );
plot ( ax3, rand(10), rand(10) );
f4 = figure;
ax4 = axes ( 'parent', f4 );
plot ( ax4, rand(10), rand(10) );
Now label axes 3:
xlabel ( ax3, 'label on plot 3' )
댓글 수: 2
dpb
2014년 7월 28일
You've got to save (or retrieve) any handles you need/refer to...Matlab doesn't know who you mean by magic. At the time you've just executed errorbar, the axes handle you need can be obtained by
hAx=gca; % retrieve, save current axes handle
errorbar returns handles to the error series objects, not the axes, similarly as plot returns line handles.
dpb
2014년 7월 25일
My goal was to graph each row separately...
Given the default orientation of Matlab and plot and errorbar to plot data by column, if you wish to use the five values as the independent variable and the others as observation, it would be better to orient the array as 5 by nColumns instead.
Then
SEM=std(Seg)/sqrt(size(Seg,1));
and you'll have the right number to use. Also it appears that you're using the wrong length in the computation as above as length()==max(size()).
Also, if use this way the line colors then should cycle automagically just as the do for plot with an array as input. If you want additional properties, use the 'LineSpec' parameter that has the same options as those for plot
Save the handle from the call to have more direct access to the properties.
Labels and titles are independent of whether use plot or any of the other graphing routines--just call title, [x|y]label, text and friends as for any other.
댓글 수: 2
dpb
2014년 7월 28일
편집: dpb
2014년 7월 28일
SEM=std(Seg)/sqrt(size(Seg,1));
...Although this does give me the proper SEM it ... only reports for 1 column and not the entire matrix...
Which is the primary reason I suggested you should reorient the data as 5xN rather than Nx5 since you're working by row and Matlab by default is column-major. Plot functions assume arrays by column and the default for functions like std() is by column, also. If you retain the other order, then you must tell std() over which dimension to operate--
SEM=std(Seg,2)/sqrt(size(Seg,2));
참고 항목
카테고리
Help Center 및 File Exchange에서 Errorbars에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!