Multi-parameter function plot with GUIDE
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all,
I'm trying to use GUIDE to plot a function that depends on 5 different parameters.
I'd like my plot to vary according to the parameters, which I want to change through sliders. What I've done so far is for each slider callback function, I'm redefining all the parameters according to the value of each sliders, and then plotting the function. (so I basically have 5 times the same code, with only one line changing each time: the parameter corresponding to the slider takes a new value). If I don't redefine all my variables, Matlab says that the other parameters are not defined.
Everything seems to work, but I feel like this is a poor code. Is there a better way to do this? (say only plot the function once, and for each slider only vary one parameter?)
Thanks in advance.
Julien
0 commentaires
Réponses (1)
Sean de Wolski
le 9 Avr 2012
Everything seems to work, but I feel like this is a poor code. Is there a better way to do this? (say only plot the function once, and for each slider only vary one parameter?)
How are you plotting the data?
I would recommend taking the "plot once modify later" approach. To do this, save the handle ( setappdata and the handles structure (or get the children of the axes)) to the plotted object (line, image, surface, - whatever it is) and maybe the axes, and update it's properties based on the new values. This could mean getting the 'xdata', or 'ydata', or 'linewidth, updating it and setting it. Since this probably isn't clear at all, here's pseudoish code for a slider callback:
function slidercallback(hObject,eventdata,handles);
hLine = get(handles.axes1,'children'); %get handle to children of axes1
%let's assume it's one line for this example
set(hLine,'linewidth',get(hObject,'value')); %set line width to slider value
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!