在MATLAB中使用补丁时出错

时间:2017-09-18 20:32:40

标签: matlab matlab-gui

我正在创建一个使用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;

1 个答案:

答案 0 :(得分:3)

patch(或包含轴句柄的4参数形式)的三参数形式要求您还为每个补丁输入color data

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]));