이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to barplot with standard deviation?
조회 수: 100 (최근 30일)
이전 댓글 표시
I've got following code so far:
if true
% code
end
load('Mean.mat') % Mean contains all mean values and consists of 5 rows
x = [time]; % define x-axis
y = [IC1,IC2,IC3,IC4]; % define y-axis
figure;
hBars = bar(y,1.0); % create bar plot with y;
set(gca,'XTickLabel',{'Baseline','0,1','0.2','0.3','0.4','0.5'});
% set ticks and tick labels
xlabel('Time');
ylabel('Impulse');
hold on;
load('standarddev.mat') % standarddev contains all calculated standard deviation and consists of 5 %rows
std = [sd1,sd2,sd3,sd4,sd5]; % define y-axis
errorbar(x,y,std);
title('Impulse');
legend('a','b','c','d','Location','SouthEastOutside')
% put in lower right
The plot itself works fine. I'd like to include the errorbars for the standard deviation as well but that unfortunately doesn't work at the moment. I've already had a look at the MATLAB Documentation Center bt without success.
Any help would be appreciated.
채택된 답변
추가 답변 (2개)
Pinga
2014년 7월 10일
Thank you, I should have done that. In the meanwhile I did but it somehow still doesn't work. Only about the half of all errorbars are plotted and still not placed in the center top of the bars (see attachment).
Since I'm new to MATLAB, I would thankful for every suggestion on my code.
if true
% code
end
load('Mean.mat') % Mean contains all mean values and consists of 5 rows
load('Stddeviation.mat')
x = [time]; % define x-axis
y = [IC1,IC2,IC3,IC4]; % define y-axis
e = [std1,std2,std3,std4,std5,std6]; % define standard deviation
figure;
hBars = bar(y,1.0,'gropued');
set(gca,'XTickLabel',{'Baseline','0,1','0.2','0.3','0.4','0.5'});
% set ticks and tick labels
xlabel('Time');
ylabel('Impulse');
hold all;
for i = 1:6;
j = 1:4;
x = -0.5 + i + 1/5 *j;
errorbar(x,y,(j,i),e(j,i),'.'); % plotting errors
end
title('Impulse');
legend('a','b','c','d','Location','SouthEastOutside')
% put in lower right
box off;
hold off;
댓글 수: 19
Star Strider
2014년 7월 10일
I can't run your code to see what the problem is. Could you attach Mean.mat and Stddeviation.mat?
Star Strider
2014년 7월 10일
This seems to work:
load('Mean.mat') % Mean contains all mean values and consists of 5 rows
load('Stddeviation.mat')
x = [time]; % define x-axis
y = [IC1,IC2,IC3,IC4]; % define y-axis
e = [sd1,sd2,sd3,sd4,sd5,sd6]'; % define standard deviation
figure;
hBars = bar(y,1.0,'grouped');
set(gca,'XTickLabel',{'Baseline','0,1','0.2','0.3','0.4','0.5'});
% set ticks and tick labels
xlabel('Time');
ylabel('Impulse');
hold all;
for i = 1:4
hb = get(get(hBars(i),'Children'), 'XData');
midbar = mean(hb);
errorbar(midbar, y(:,i), e(:,i), '.') % plotting errors
end
title('Impulse');
legend('a','b','c','d','Location','SouthEastOutside')
% put in lower right
box off;
hold off;
Pinga
2014년 7월 11일
Thank you a lot! That was really helpful - I appreciate it!
One more problem: The code actually runs only after hitting "Run" a second time. The first time I'm running it, it'll only plot the bars without errorbars. Following error appear then: "Error using handle.handle/get. Invalid or deleted object." Indicated line is
if true
% code
end"
hb = get(get(hBars(i),'Children','Xdata');
I've already cleared workspace and deleted the two .mat-files Mean and Stddeviation and created them a second time in MATLAB. I've checked for the correct path in MATLAB and I also tried to run the code on another device - I'm getting the same error message.
Star Strider
2014년 7월 11일
It runs for me without errors, warnings, or other problems. (I’m running R2014a, so there could be version differences.) The code I used is exactly what I posted (tested first). It might be worthwhile to remove the semicolon on the ‘hBar = bar( ... )’ line to be sure the handle is returned and has the correct dimensions.
I usually caution against using ‘i’ and ‘j’ as loop counters because MATLAB uses them for its imaginary operators. Changing the loop counter to ‘k’ might solve the problem, but since I can’t reproduce it, I can’t help you with it.
Pinga
2014년 7월 11일
Thank you for your help. I'm also running R2014a on both devices I've tried... That makes sence, I only used 'i' and 'j', since I saw it on another site when I was researching how to solve this errorbar-problem. So, I've already changed it to k. It's "just" a flaw and therefore not really a problem, if I won't find the solution for it.
Thank you again for your help - I really appreciate your time and effort!
Star Strider
2014년 7월 11일
My pleasure.
I don’t know what could be causing your problem. The hBars variable should exist, and I can’t see that it’s being overshadowed anywhere, at least in my code snippet. The only other suggestion I have is to put:
clear hBars
before the ‘x = time;’ statement to be sure you don’t have another hBars variable somewhere else.
Pinga
2014년 7월 11일
I made sure that none of the variables have been used anywhere before. If I have solved the problem, I'll comment once again.
Thank you and have a great day!
Star Strider
2014년 7월 11일
편집: Star Strider
2014년 7월 11일
My pleasure! You too!
I wish I could help, but I can’t reproduce your problem. The code I posted runs for me without errors or warnings, and the plot looks as it should.
The only thing I can think of is to break up the one hb line into two separate statements:
hbc = get(hBars(k1),'Children');
hb = get(hbc, 'XData');
and see if that somehow magically solves the problem. At least it might tell you which one of the previously nested commands is throwing the error.
Pinga
2014년 7월 12일
Unfortunately, it doesn't magically solve the problem. I'll just keep trying. You've been really helpful - thanks!
Star Strider
2014년 7월 12일
My pleasure!
Can you reproduce it on other computers? That could provide some insight. I can’t reproduce it on mine.
Star Strider
2014년 7월 14일
편집: Star Strider
2014년 7월 14일
Which line — hbc or hb — throws the error?
Since I can’t reproduce the error, I submitted a Service Request to TMW to see if they can reproduce it and suggest a solution.
Pinga
2014년 7월 14일
Wow - you're making a great effort - thank you! I'll get the error message on
if true
% code
end
hbc = get(hBars(k),'Children');
I don't know, if this is of any relevance but MATLAB doesn't show any warnings, thus the box on the upper right corner appears grean (I'm using default settings).
Star Strider
2014년 7월 14일
That’s strange, because each of the hBars handles should work without problems. I sent along the URL to this thread in my Service Request, so they’ll see everything here.
I’m mystified by ‘the box on the upper right corner’. Your installation must be configured differently than mine.
Star Strider
2014년 7월 18일
I received a reply from TMW with respect to your problem. The essence of the reply follows. (Note: ‘Feel free to let him know that he can contact us directly if he is still having issues. We would be happy to help him directly and, in that case, taking a closer look at what is happening with screen sharing would be the best option.’)
--------------------------------------------------
I read the conversation on MATLAB Answers and ran the code that you posted. It also works fine on my computer.
The error message is clear: one of the handles in the "hBars" vector, or one of the children of one of these objects, refers to an object that does not exist anymore. This would typically happen if the figure was closed.
Unfortunately, I cannot help him anymore than you already did without having access to his computer. The first suggestion would be to step through the code and look at the handles in "hBars" and their children after calling "bar" and after each "get" call, making sure that they exist.
I would also suggest to check that the "bar" function is not shadowed by something else with
>> which -all bar
It could be possible that there is a function named "bar" on the path that returns a double (assuming he is using MATLAB R2014a or older) without throwing an error for these input arguments. In that case, the output would not a valid handle.
That fact that the error bars in the PDF he attached are off is very strange. That could indicate that there is something wrong with his data (e.g., he changed the value of "y" midway through the script) or with his files. It could be possible that he did not run the script at once (F5) but he executed lines here and there without clearing the workspace and closing all the figures.
I would also take a look at the renderer used to display the figure and ask if he changed any of the defaults properties of the graphics root object 0.
Feel free to let him know that he can contact us directly if he is still having issues. We would be happy to help him directly and, in that case, taking a closer look at what is happening with screen sharing would be the best option.
Again, I apologize that I could not be more helpful. I am now closing this case as unresolved. Please let me know if you have additional questions
--------------------------------------------------
Pinga
2014년 7월 21일
Thank you a lot for posting the reply. I haven't been able to solve the problem in the last few days. Next step is to try the suggestions mentioned above. How do I get in contact with TMW, if I still having issues?
Star Strider
2014년 7월 21일
My pleasure!
To get in touch with TMW, start at the TMW home page, go to the upper right, click on ‘My Account’ then on the ‘MathWorks Account’ page, on the left under ‘My Account’, click on ‘Create Service Request’ and choose the ‘Technical Support’ option. Follow the instructions. Include the URL to this thread in your Service Request. No need to explain it all again when you’ve already explained it here. You will also need to type ver in the Command Window to get the version information for your MATLAB installation.
TMW should be able to solve your problem.
Pinga
2014년 7월 10일
What I've tried is to switch the columns/rows since the last plot only showed four groups of errorbars. But that didn't solve the problem. I left the values for the standard deviation in this switched order.
That would be great, if anyone could help me - I've been trying for some days now to only plot these data.
참고 항목
카테고리
Help Center 및 File Exchange에서 Errorbars에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)