what does this error mean (Error using matlab.graphics.axis.Axes/set )
28 次查看(过去 30 天)
显示 更早的评论
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
2017-8-17
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:
- 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
- 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...
- 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 个评论
Walter Roberson
2017-8-19
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.
Image Analyst
2017-8-19
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!