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