Assigning plot to an existing axes Matlab GUI
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hi, I have a GUI in Matlab and several functions in it. One function is for plotting a figure, I need to assign it to an existing axes in GUI. I have tried several options, nothing has worked out yet.
Code below is the current option I had tried before I asked here.
set('CurrentAxes','axes11')
plot(VyQRS(:,2));
grid on
The plot of VyQRS I need to assign to axes11. Could you please give me any hint?
채택된 답변
Image Analyst
2017년 2월 12일
Try this:
axes(handles.axes11); % Switch current axes to axes11.
plot(VyQRS(:,2)); % Will plot into axes11.
grid on
댓글 수: 8
Didn't work out. Error:
Undefined variable "handles" or class "handles.axes10".
This is the code for the button:
% --- 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 = QRS_points (Data.fileData(:,1), Data.fileData(:,2),Data.fileData(:,3))
save 'pointsQRS.mat' -mat pointsQRS
Try to obtain the handles struct:
handles = guidata(hObject);
Code for the button:
% --- 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)
handles = guidata(hObject);
pointsQRS = QRS_points (Data.fileData(:,1), Data.fileData(:,2),Data.fileData(:,3))
save 'pointsQRS.mat' -mat pointsQRS
Code of the function:
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
Error:
Undefined variable "handles" or class "handles.axes10".
What is "the function"? If it's a callback, you should already have handles in there and it should not give you that error. If you have your own function you wrote, then you'll need to pass handles into it so that it can see handles.
For the first function you show, pushbutton4_Callback(), you should have the guidata() call be the last line of code in the function, not the first.
Finally, I have no idea why the error mentions handles.axes10 since you don't even reference that axes. You only reference axes11, NOT axes 10. It leads me to believe that you're not showing me all the code. I know for a fact that you're not showing all the error message because the full error message has things like the line number and the actual line of source code that threw the error. Why you chose to just snip out a small snippet of the error message and not share the entire error message ( ALL the red text), I have no idea. Please always include the entire error message if you want help.
Franta Cymorek
2017년 2월 12일
편집: Franta Cymorek
2017년 2월 12일
Full error:
Undefined variable "handles" or class "handles.axes10".
Error in QRS_points (line 6)
axes(handles.axes10);
Error in VKG_Zobrazovac>pushbutton4_Callback (line 155)
pointsQRS = QRS_points (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,event data,guidata(hObject))
Error while evaluating UIControl Callback
It should be axes11, not 10, my mistake. And yes, for the push button I have written my own function. Here I reupload the function again:
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
That's how it looks now the function.
Jan
2017년 2월 12일
Did you understand, what the "handles" struct contain and how it is provided to other callbacks? You can use the handle of the "axes11" only, if you have stored it such, that you can you it where it is required. If the handle of teh "axes11" is stored in the handles struct, you can used it, if this struct is available, e.g. by obtaining it by guidata, get/setappdata, storing it in the UserData, etc. You find many corresponding threads in this forum. I assume, that your problem can be solved very fast, but currently there is always the one or other tiny detail missing in the explanantions. But actually it is trivial: Care to providing the required axes handle.
To fix you need to pass handles into your custom pushbutton function:
function MyCustomPushButtonFunction(handles)
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
Then, in a callback function, which automatically has access to handles, or some other function that has access to handles, you must call your custom function and pass handles to it:
MyCustomPushButtonFunction(handles); % Call your custom function.
Franta Cymorek
2017년 2월 13일
편집: Franta Cymorek
2017년 2월 13일
Still does not work. Did exactly what You told me to do.
Error:
Undefined function or variable 'VxQRS'.
Error in VKG_Zobrazovac>pushbutton4_Callback (line 156)
x_pointsQRS = MyCustomPushButtonFunctionQRS10(VxQRS);
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,event data,guidata(hObject))
Error while evaluating UIControl Callback
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
