How can I use sliders to do interactive plots from a structure array?
Afficher commentaires plus anciens
I have a structure array containing a B number of matrixes of [MxN] data, where M is different for every set and N is the same for every set of data.
I would like to have only one plot, where using two sliders I can choose between the B sets of data and N columns. I have only found examples of how to use a slider to update a plot changing a parameter (like the damping factor of a sinusoid), but nothing useful for my case.
4 commentaires
Stijn Haenen
le 4 Août 2020
Something like this:
close all
clear
b=struct;
for i=1:10
b(i).data=ones(10)*i.*(i:i:i*10); %creating struc with data
end
fig = figure;
s1 = uicontrol('Parent',fig,'Style','slider','Position',[81,1,419,23],...
'value',0.1, 'min',0.1, 'max',10);
s2 = uicontrol('Parent',fig,'Style','slider','Position',[81,24,419,23],...
'value',0.1, 'min',0.1, 'max',10); %creating sliders
hold on
while 1>0
plot(b(ceil(s1.Value)).data(:,ceil(s2.Value)),'b') %plot data
pause(0.1)
delete(fig.CurrentAxes.Children)
end
Seth Meiselman
le 17 Sep 2020
Could you give an example of this structure array- how you've composed it in code? I think the solution above seems reasonable unless there is something specific about how you've constructed this data set. Are the matrices enumerated or labeled in the structure?
Alessandro Giacetti
le 17 Sep 2020
Rik
le 17 Sep 2020
If you write code using that callback (and I encourage you to try something yourself), make sure to round the value, as you're not guaranteed an integer.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!