How can I use sliders to do interactive plots from a structure array?
Mostrar comentarios más antiguos
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 comentarios
Stijn Haenen
el 4 de Ag. de 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
el 17 de Sept. de 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
el 17 de Sept. de 2020
Rik
el 17 de Sept. de 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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!