Start plot errorbar() at 0 ?

조회 수: 2 (최근 30일)
Remi Chaussenot
Remi Chaussenot 2015년 4월 27일
편집: Remi Chaussenot 2015년 4월 28일
Hello,
In my matlab script, i use errorbar() to plot my data, but i wish it could start from 0 (for the y-axis).
Do you have an idea ?
Thanks !
Here is my sample :
>> x
moyenne(2:2,1:end)
ste(1:1,1:end)
x =
1 2
ans =
64.7573 36.0701
ans =
4.0268 4.6105
>> errorbar(x,moyenne(2:2,1:end),ste(1:1,1:end));

채택된 답변

Jos (10584)
Jos (10584) 2015년 4월 27일
You can change limits of the axis using the commands YLIM
CurYLim = ylim % get the current Y limits
ylim([0 CurYlim(2)]) % change the lower limit

추가 답변 (1개)

Remi Chaussenot
Remi Chaussenot 2015년 4월 27일
Thanks for your quick answer.
In the mean time, i ended with :
oldy = get(gca, 'ylim')
if oldy(1) > '0'
oldy = [0 oldy(2)]
end
set(gca,'YLim',[0 oldy(2)])
Which one is better ?
Thanks :)
  댓글 수: 2
Michael Haderlein
Michael Haderlein 2015년 4월 27일
First, please note that the '' in your if statement are making things wrong. You actually compare the lower limit with the string '0'. This means, the value of the ascii sign '0' will be used which is 48. So you set oldy(1) to zero only if it was at least 49 before. That's not what you wanted, I guess.
However, your code works because the if structure makes nothing at all. The reason is that you don't even use the value of oldy(1) in your set statement. So you can simply delete the entire if statement. What you then end up with is basically the same as Jos' answer. If you use ylim() or set(handle,'ylim',..) is up to you.
Remi Chaussenot
Remi Chaussenot 2015년 4월 28일
편집: Remi Chaussenot 2015년 4월 28일
Hello,
I had some difficulties to understand your message yesterday, so i reply just today.
"You actually compare the lower limit with the string '0'. This means, the value of the ascii sign '0' will be used which is 48. So you set oldy(1) to zero only if it was at least 49 before. That's not what you wanted, I guess."
No, you guess well. I do not know that it use the ascii value with ' ' (well, started with MATLAB a few weeks ago, more used at PHP/JS...).
"The reason is that you don't even use the value of oldy(1) in your set statement. So you can simply delete the entire if statement."
Damned, i just read my code today. Yeah, the if statement is truly useless, because the set is outside ! Was very tired yesterday..
Thanks for opening my eyes Michael :)
Edited like that :
CurYLim = ylim
if CurYLim(1) > 0
ylim([0 CurYLim(2)])
end
Seems okay ? Thanks Michael and Jos :-)

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

카테고리

Help CenterFile Exchange에서 Errorbars에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by