필터 지우기
필터 지우기

How to update Axes LineStyle Order in Matlab Gui

조회 수: 3 (최근 30일)
Ravi Goyal
Ravi Goyal 2015년 10월 13일
답변: Ravi Goyal 2015년 11월 3일
Dear Community,
I want to change the Linestyle of a Matlab Figure in a Gui. I have a popupmenu with a switch case structure where I can set the property. However, no change occurs whatsoever. I tried whats in commentary with refresdata and so forth, but no change. Do I need to replot all the data with plot (yet I dont know at all times which data I have. Or is there another way for it to update the figure?
Thanks a lot, below the code Ravi
switch get(hObject,'Value')
case 1
set(handles.axes_eis,'LineStyleOrder', '-');
guidata(hObject, handles);
% refreshdata(handles.axes_eis)
% refreshdata(handles.axes_eis,'caller')
% draw now
case 2
set(handles.axes_eis,'LineStyleOrder', '.-');
guidata(hObject, handles);
end
guidata(hObject, handles);

채택된 답변

Ravi Goyal
Ravi Goyal 2015년 11월 3일
I figured it out. Seems I only need to set the marker of the children in the plot. The Code I used
% --- Executes on selection change in lines_or_points.
function lines_or_points_Callback(hObject, eventdata, handles)
all_child_handles_axes_eis=get(handles.axes_eis,'Children');
all_child_handles_axes_drt=get(handles.axes_drt,'Children');
switch get(handles.lines_or_points, 'Value');
case 1 %LINES
set(all_child_handles_axes_eis(1:end), 'Marker', 'none')
set(all_child_handles_axes_drt(1:end), 'Marker', 'none')
case 2 %POINTS
set(all_child_handles_axes_eis(1:end), 'Marker', '.')
set(all_child_handles_axes_drt(1:end), 'Marker', '.')
end

추가 답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 10월 17일
Ravi - is the LineStyleOrder of the axes that you wish to change or the LineStyle of the curve plotted within the axes? I think that it may be the latter that you wish to change. If that is the case, then you will need to do something like the following in your popup menu callback
switch get(hObject,'Value')
case 1
set(handles.hPlot,'LineStyle', '-');
case 2
set(handles.hPlot,'LineStyle', '.-');
end
where handles.hPlot is the handle to the graphics object that was plotted using (for example) plot. The initialization of this field within handles may have occurred elsewhere in your code as
handles.hPlot = plot(...);
guidata(hObject,handles);
The first line is just the call to plot some data with the handle to the graphics object set in the hPlot field of handles. We then save this change to the updated handles object using guidata.
  댓글 수: 2
Ravi Goyal
Ravi Goyal 2015년 10월 22일
편집: Ravi Goyal 2015년 10월 22일
Hi Geoff, thanks for getting back. Tried your suggestion, however ran into following problem:
Error using set
Bad property value found.
Object Name: line
Property Name: 'LineStyle'.
Error in FIT_GUI>lines_or_points_Callback (line 207)
set(handles.hPlot,'LineStyle', '.-');
I named my handle as you suggested (even tried it as hplot) Wonder, if guidata has sth to do with it. My plot happens in a function I only pass "handles"
function plot(handles)
...
handles.hplot=plot(...)
guidata(handles.tag_of_gui, handles)
end
Any Idea, what this might be caused by? Thanks a bunch! Ravi
Geoff Hayes
Geoff Hayes 2015년 10월 22일
Ravi - you shouldn't create a function named plot since that conflicts with the built-in MATLAB function of the same name. What happens at the line of code
handles.hplot = plot(...);
Is plot the MATLAB function or yours? Please rename your function to something else and try again.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by