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

27 ビュー (過去 30 日間)
Nora Khaled
Nora Khaled 2017 年 8 月 17 日
コメント済み: Nora Khaled 2017 年 8 月 20 日
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 件のコメント
Nora Khaled
Nora Khaled 2017 年 8 月 19 日
編集済み: Walter Roberson 2017 年 8 月 19 日
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
Nora Khaled 2017 年 8 月 20 日
thank you, the problem was solved.

サインインしてコメントする。

回答 (2 件)

Walter Roberson
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:
  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 件のコメント
Walter Roberson
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.
Nora Khaled
Nora Khaled 2017 年 8 月 20 日
thank you so much. turned out that that was the problem. because tA, tB,and tC are arrays.

サインインしてコメントする。


Image Analyst
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 ExchangeConway's Game of Life についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by