imagesc does not take an axis handle as its first argument even if it should

7 次查看(过去 30 天)
According to the documentation (https://www.mathworks.com/help/matlab/ref/imagesc.html), imagesc should take as an optional first argument an axis handle. However, I get errors when I try this:
fig = figure;
ax = fig.CurrentAxes;
imagesc(ax, [1,2;3,4])
The output is this:
>> test
Dot indexing is not supported for variables of this type.
Error in imagesc (line 48)
elseif any(strcmpi(cax.NextPlot,{'replaceall','replace'}))
Error in test (line 3)
imagesc(ax, [1,2;3,4])
Using a much bigger script, I also got the following error, which I am unable to reproduce with a short script:
Error using image
Incorrect number of arguments.
Error in imagesc (line 40)
hh = image(varargin{:},'CDataMapping','scaled');
Error in testbed2_generateF (line 93)
imagesc(ax, [N_BS(1), N_BS(end)], [N, N], log10(errF))

采纳的回答

Steven Lord
Steven Lord 2018-9-19
Look at the variable ax.
>> fig = figure;
ax = fig.CurrentAxes
ax =
0×0 empty GraphicsPlaceholder array.
That's not an axes. When you create a figure, it doesn't have an axes on it unless you've specifically set up a CreateFcn or something similar that adds an axes. [When you call a plotting function like plot it creates the figure then creates an axes on that figure and finally creates the plot on the axes.] Compare with:
>> fig = figure;
axes(fig);
ax = fig.CurrentAxes
ax =
Axes with properties:
...
The error message could probably stand to be a bit more descriptive. If you feel strongly about that, I recommend submitting that to Technical Support as an enhancement request using the Contact Us link in the upper-right corner of this page.
  1 个评论
Alec Poulin
Alec Poulin 2018-9-20
Hi, this is a very good answer, thank you!
I just noticed that in my longer script, I use hold on right after fig = figure;, which seems to add axes in the figure. Without hold on, all the xlim, ylim, plot, and contour functions of the script return errors. The funny part is that these errors are not the same:
  • xlim and ylim say Invalid or deleted graphics object.
  • plot says Parent must be a scalar graphics handle.
  • contour says Input arguments must be real. Use the function REAL to get the real part of the inputs.
Now my question is how to make the call to imagesc work. I thought the problem was caused by ax, because it worked when I removed it. I will have to investigate a little bit more.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by