2

我正在创建一个使用该patch功能进行放大的拖动框。拖动时出现以下错误:

Error using patch
Not enough input arguments.

Error in boxReady (line 31)
guiele.dragBox = patch(guiele.ResponsePlotAxis, ...
                       repmat(vabls.CurrentPoint(1,1),[1 4]), ...
                       repmat(vabls.CurrentPoint(1,2),[1 4]));

这是我正在使用的代码:

% This is the point the cursor is at when the user presses down. drawBox is called again
% when the button is released and the current point then is the other corner of the patch
vabls.CurrentPoint = get(guiele.ResponsePlotAxis,'CurrentPoint');

set(guiele.ResponsePlotLine,'erasemode','none');

XYLims=[get(guiele.ResponsePlotAxis,'xlim') get(guiele.ResponsePlotAxis,'ylim')];

axes(guiele.ResponsePlotAxis);
hold on;
if ishandle(guiele.dragBox)
    delete(guiele.dragBox);
end
guiele.dragBox = patch(guiele.ResponsePlotAxis, ...
                       repmat(vabls.CurrentPoint(1,1),[1 4]), ...
                       repmat(vabls.CurrentPoint(1,2),[1 4]));
set(guiele.dragBox,'FaceColor','none','EdgeColor','r','LineStyle',':');

% initialize some varaiables
guiele.ResponsePlotAxis=-1;
guiele.dragBox = -1;
4

1 回答 1

3

的三参数形式patch(或包括坐标轴句柄的四参数形式)要求您还为每个色块输入颜色数据:

patch(X, Y, C);
% Or ...
patch(ax, X, Y, C);

如果不想输入颜色数据,可以使用下面的表格:

patch(ax, 'XData', X, 'YData', Y);

所以你的电话patch看起来像这样:

guiele.dragBox = patch(guiele.ResponsePlotAxis, ...
                       'XData', repmat(vabls.CurrentPoint(1, 1), [1 4]), ...
                       'YData', repmat(vabls.CurrentPoint(1, 2), [1 4]));
于 2017-09-18T20:44:57.397 回答