How can I use selections from multiple uidropdowns as function inputs?
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm using two (2) uidropdowns with a valuechangedfcn to live update the x-y axes for a plot based on the selected variable. I can't figure out how to simultaneously pass the information from both dropdowns to my plotting function. For example, say I have data for three variables: time, position, and velocity, and I have two drop downs each containing the same three variables for the x and y axes. I'm unable to retain a previous variable selection for the x-axis once I select a new variable for the y-axis, so it just reverts to the initialized x-variable. Is there a way to store the selection from each dropdown simultaneously
0 commentaires
Réponses (2)
Walter Roberson
le 8 Juil 2024 à 21:25
Inside the plotting function, access the uidropdown value property directly for the two controls.
xval = app.XDropDown.Value;
yval = app.YDropDown.Value;
0 commentaires
Voss
le 8 Juil 2024 à 21:27
Here's an example of how it could work:
function uidropdown_demo()
T = array2table([(1:25).' [10 100].*rand(25,2)], ...
'VariableNames',{'time','position','velocity'});
f = uifigure();
ax = uiaxes(f, ...
'Position',[20 20 400 300]);
xdd = uidropdown(f, ...
'Items',T.Properties.VariableNames, ...
'Position',[20 340 100 26], ...
'ValueChangedFcn',@vcf);
ydd = uidropdown(f, ...
'Items',T.Properties.VariableNames, ...
'Position',[220 340 100 26], ...
'ValueChangedFcn',@vcf);
vcf() % initialize the plot
function vcf(~,~)
plotFunction(xdd.Value,ydd.Value)
end
function plotFunction(x,y)
cla(ax)
plot(ax,T.(x),T.(y));
xlabel(ax,x);
ylabel(ax,y);
end
end
0 commentaires
Voir également
Catégories
En savoir plus sur Annotations 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!