# what does this error mean (Error using matlab.gra​phics.axis​.Axes/set )

조회 수: 156(최근 30일)
Nora Khaled 17 Aug 2017
Commented: Nora Khaled 20 Aug 2017
Hi!
I want to make a plot where the Maximilian point to be plotted are 5. but I keep getting this error message:
----
Error using matlab.graphics.axis.Axes/set
While setting the 'YLim' property of Axes:
Value must be a 1x2 vector of numeric type in which the
second element is larger than the first and may be Inf
Error in axis>LocSetLimits (line 200)
set(ax,...
Error in axis (line 93)
LocSetLimits(ax(j),cur_arg);
Error in CongestionGame (line 216)
axis([plot_axis_x1 plot_axis_x2 plot_axis_y1
plot_axis_y2]);
----
this is the code for plotting:
if(game>5)
plot_axis_x1=game-5;
plot_axis_x2=game;
else
plot_axis_x1=0;
plot_axis_x2=5;
end
plot_axis_y1=min(tA,min(tB,tC)) - 50 ;
plot_axis_y2=max(tA,max(tB,tC)) + 50 ;
while(k>0 && k>(game-5))
plot_x(k)=k;
plot_ya(k)=tA(k);
plot_yb(k)=tB(k);
plot_yc(k)=tC(k);
k=k-1;
end %end while k>0
%PLOT:
plot(plot_x, plot_ya,'r',plot_x,plot_yb,'b',plot_x,plot_yc,'g');
axis([plot_axis_x1 plot_axis_x2 plot_axis_y1 plot_axis_y2]);
the code works perfectly when game is 1.
how ever on game 2 the problem accrue.

#### 댓글 수: 5

표시 이전 댓글 수: 2
Walter Roberson 17 Aug 2017
At the command prompt, give the command
dbstop if error
then allow the program to run. It will stop and open the code for axis . At that point give the command
dbup
and keep giving that command until it tells you that you are in the workspace for CongestionGame . At that point show us the result of
format long g
[plot_axis_x1 plot_axis_x2 plot_axis_y1 plot_axis_y2]
Nora Khaled 19 Aug 2017
K>> format long g
[plot_axis_x1 plot_axis_x2 plot_axis_y1 plot_axis_y2]
ans =
Columns 1 through 2
0 5
Columns 3 through 4
177.8 105.8
Columns 5 through 6
429.8 580.2
K>>
this is the results.
Nora Khaled 20 Aug 2017
thank you, the problem was solved.

로그인 to comment.

### 답변 수 (2)

Walter Roberson 17 Aug 2017
Suppose game = -2 at the time your program runs. Then if(game>5) would be false, so the "else" would take effect, setting plot_axis_x1=-1 . Then you have plot_axis_x2=game; which would (in this hypothetical situation) be -2. Your axes() call would then be trying to set the x axis to [-1 -2] which would not be allowed.
However we see the error message is about YLim, which you have set with the pair min(tA,min(tB,tC)) - 50 and max(tA,max(tB,tC)) + 50 . One might think that could hardly go wrong along the same kinds of lines that I just showed could be a problem with x. But look more carefully:
1. suppose tA, tB, and tC are all NaN, then the min() and max() would give back NaN, and Nan-50 and Nan+50 would both be NaN, leading to a situation where the second value was not greater than the first
2. suppose tA, tB, and tC are all inf or all -inf, then the min() and max() would give back that inf or -inf, and inf +/- 50 is inf and -inf +/- 50 is -inf, so you would get a situation where the values are equal...
3. suppose that the absolute values involved exceed approximately 1.15E+18 . Then because values have a finite precision, the value minus 50 and the value plus 50 are all the same number to within floating point precision. Then the second value would be bitwise equal to the first value, which would not be greater than the first value.

#### 댓글 수: 3

Nora Khaled 17 Aug 2017
the thing is I could see the values assigned to plot_axis_y1 and plot_axis_y2 after the program stops due to the message and they are correct number since plot_axis_y1<plot_axis_y2.
Walter Roberson 19 Aug 2017
If we look at the code
plot_ya(k)=tA(k);
plot_yb(k)=tB(k);
plot_yc(k)=tC(k);
we can see that tA, tB, and tC are all expected to be vectors.
You have
plot_axis_y1=min(tA,min(tB,tC)) - 50 ;
the min(tB,tC) is going to be a vector the same length as that vector. min(tA, that vector) is going to be a vector the same length. Therefore your plot_axis_y1 and plot_axis_y2 are going to be vectors rather than scalars.
Suppose that tA, tB, and tC are vectors of length 2. Then, when you then construct
[plot_axis_x1 plot_axis_x2 plot_axis_y1 plot_axis_y2]
then the first item will be a scalar, the second item will be a scalar, the third item will be a vector of length 2, and the fourth item will be a vector of length 2, leading to a total length 1+1+2+2 = 6 .
It is not an error to call axes() with a vector of length 6, because it is legal to call axes() with x, y, and z components. But when you look at what it is receiving as the y components, 177.8 105.8 then you will notice they are out of order.
You are constructing your plot_axis_y1 and plot_axis_y2 incorrectly, failing to take into account that you are dealing with vector tA, tB, tC.
Nora Khaled 20 Aug 2017
thank you so much. turned out that that was the problem. because tA, tB,and tC are arrays.

로그인 to comment.

Image Analyst 19 Aug 2017
You might find it easier and more explicit to call xlim(), ylim() and zlim() separately:
xlim([0, 42]);
ylim([-pi, 77]);
zlim([sind(45), exp(2)]);
Pass each function the low and high limits that you want to use for that axis.

#### 댓글 수: 1

Nora Khaled 20 Aug 2017
thank you, the problem was solved.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by