从函数在轴上绘制



我正在MATLAB中开发GUI;我在命令窗口中使用了指南。我有几个按钮。现在的问题,我有一个函数,在一个pusbhbutton4,当我点击它时,我想在三个特定的轴(10 - 12(上绘制结果。但不起作用。

代码:

function pointsQRS = MyCustomPushButtonFunctionQRS10(VxQRS, VyQRS, VzQRS)
VxQRS=[[0:length(VxQRS)-1]' VxQRS];
axes(handles.axes10);
plot(VxQRS(:,2));
grid on 
Vx_QRS=ginput; 
x_pointsQRS=VxQRS(Vx_QRS(1,1)<=VxQRS(:,1) &  Vx_QRS(2,1)>=VxQRS(:,1),:);
m=1;

VyQRS=[[0:length(VyQRS)-1]' VyQRS];
axes(handles.axes11);
plot(VyQRS(:,2));
grid on
Vy_QRS=ginput; 
y_pointsQRS=VyQRS(Vy_QRS(1,1)<=VyQRS(:,1) & Vy_QRS(2,1)>=VyQRS(:,1),:);
if size(y_pointsQRS,1)<m
 m=2;
 end

  VzQRS=[[0:length(VzQRS)-1]' VzQRS];
  axes(handles.axes12);
  plot(VzQRS(:,2));
  grid on
  Vz_QRS=ginput; 
  z_pointsQRS=VzQRS(Vz_QRS(1,1)<=VzQRS(:,1) & Vz_QRS(2,1)>=VzQRS(:,1),:);
  if size(z_pointsQRS,1)<m
    m=3;
  end

  switch m 
   case 1
    x_pointQRS=x_pointsQRS;                                                                   
    y_pointQRS=y_pointsQRS(x_pointsQRS(1,1)<=y_pointsQRS(:,1) &    x_pointsQRS(end,1)>=y_pointsQRS(:,1),:);
    z_pointQRS=z_pointsQRS(x_pointsQRS(1,1)<=z_pointsQRS(:,1) &  x_pointsQRS(end,1)>=z_pointsQRS(:,1),:);
case 2
    y_pointQRS=y_pointsQRS;
    x_pointQRS=x_pointsQRS(y_pointsQRS(1,1)<=x_pointsQRS(:,1) & y_pointsQRS(end,1)>=x_pointsQRS(:,1),:);
    z_pointQRS=x_pointsQRS(y_pointsQRS(1,1)<=z_pointsQRS(:,1) & y_pointsQRS(end,1)>=z_pointsQRS(:,1),:);
case 3
    z_pointQRS=z_pointsQRS;
    x_pointQRS=x_pointsQRS(z_pointsQRS(1,1)<=x_pointsQRS(:,1) & z_pointsQRS(end,1)>=x_pointsQRS(:,1),:);
    y_pointQRS=y_pointsQRS(z_pointsQRS(1,1)<=y_pointsQRS(:,1) & z_pointsQRS(end,1)>=y_pointsQRS(:,1),:);
 end

 size_min=min([size(x_pointQRS,1) size(y_pointQRS,1) size(z_pointQRS,1)]) 
 pointsQRS([1:size_min],:)=[x_pointQRS([1:size_min],2)        y_pointQRS([1:size_min],2) z_pointQRS([1:size_min],2)];
      if size_min==0
       error('Wrong.');
       end
      end

按钮代码:

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, Data)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

pointsQRS = MyCustomPushButtonFunctionQRS10(Data.fileData(:,1), Data.fileData(:,2), Data.fileData(:,3))

save 'pointsQRS.mat' -mat pointsQRS

我仍然收到错误:

Undefined variable "handles" or class "handles.axes10".
Error in MyCustomPushButtonFunctionQRS10 (line 3)
axes(handles.axes10);
Error in VKG_Zobrazovac>pushbutton4_Callback (line 156)
pointsQRS = MyCustomPushButtonFunctionQRS10(Data.fileData(:,1), Data.fileData(:,2), Data.fileData(:,3))
Error in gui_mainfcn (line 95)
        feval(varargin{:});
Error in VKG_Zobrazovac (line 42)
    gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)VKG_Zobrazovac('pushbutton4_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating UIControl Callback

你能给我任何提示如何让它正常工作吗?

您没有将handles结构传递给MyCustomPushButtonFunctionQRS10(或您称之为Data(,因此它无法访问存储在handles中的axes句柄。应将handles作为输入参数传递。

pointsQRS = MyCustomPushButtonFunctionQRS10(Data.fileData(:,1), ...
                                            Data.fileData(:,2), ...
                                            Data.fileData(:,3), ...
                                            Data)

然后你的回调将接受第四个输入

function pointsQRS = MyCustomPushButtonFunctionQRS10(VxQRS, VyQRS, VzQRS, handles)

此外,我建议使用 plot'Parent' 属性来指定父轴,而不是使用 axes

plot(VxQRS(:,2), 'Parent', handles.axes10);
grid(handles.axes10, 'on')
Vx_QRS = ginput(handles.axes10); 

相关内容

  • 没有找到相关文章

最新更新