How can i make this drop down menu in GUI change the line style of my graph

5 views (last 30 days)
Hello all, i'm currently working on a project that creates a GUI that plots functions of any type. One thing i would like it to do is be able to vary the line style (solid,dashed, etc.). Having not been taught GUI i have trouble coding. I currently have this in my popupmenu callback
if true
% code
dstr = get(hObject, 'String');
val = get(hObject,'Value');
% Set current data to the selected data set.
switch str{val};
case 'Solid line'
handles.current_data = handles.solid;
case 'Dashed line'
handles.current_data = handles.dashed;
case 'Dotted line'
handles.current_data = handles.dotted;
case 'Dash-dot line'
handles.current_data = handles.dashdot;
end
guidata(hObject,handles)
end
I then go to my push button to create the graph and i add line=get(handles.popupmenu1,'String'); thinking that when i go to plot i could place plot(....'linestlye', line) to get the desired linestyle.
Also i defined the handles in the pop up menu in the opening function as the following
if true
% code
solid='-'
dashed='--'
dotted=':'
dashdot='-.'
handles.solid=solid
handles.dashed=dashed
handles.dotted=dotted
handles.dashdot=dashdot
end Any help would be greatly appreciated!

Answers (1)

Walter Roberson
Walter Roberson on 6 Apr 2014
Be sure to guidata() after you initialize handles.solid and so on.
To put the change into effect you need to have the handles of the lines to be affected. You might have recorded those, or you might know the axes they are in.
set(findobj(handles.TheAppropriateAxes, '-type', 'line'), 'LineStyle', handles.current_data);

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!