How can i reset a plotted line everytime I draw a new one?
8 views (last 30 days)
Show older comments
Hi, a big novice when using matlab and i've been using guide to create a gui. In my gui i wish to have a pop-up menu which can plot lines of the selected data on the axis. I've gotten this to work, my issue is each time i select a new feature on the drop down it merely draws a new line and keeps the old ones. Is there a way to maybe add a limit to the amount of lines drawn on the axes, which when you draw a new one after the limit, the first line is replaced?
At the moment my code is just a simple switch case:
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
contents = get(handles.popupmenu1,'Value');
num = get(handles.bigbox,'UserData');
switch contents
case 1
n = 1;
case 2
n = 2;
case 3
n = 3;
case 4
n = 4;
case 5
n = 5;
case 6
n = 6;
case 7
n = 7;
case 8
n = 8;
case 9
n = 9;
case 10
n = 10;
case 11
n = 11;
case 12
n = 12;
case 13
n = 13;
case 14
n = 14;
case 15
n = 15;
case 16
n = 16;
otherwise
n = 17;
end
t = num(n,4):4:num(n,5);
y = 10.^(num(n,1) - (num(n,2)./(num(n,3) + t)));
line(t,y);
Not part of this question but also, if there would be a way to make that a bit more condensed information would be greatly appreciated. Also a way of making each line a different colour would be good! :)
Sorry if this is a newbie question and the answer is somewhere inside the matlab help, i've tried looking and found no solution.
0 Comments
Accepted Answer
Sara
on 25 Apr 2014
Before plotting the new variable:
delete(fig_handle)
and replace the last line in your code with:
fig_handle = line(t,y);
You can also eliminate the switch with:
if contents < 17
n = contents;
else
n = 17;
end
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!