How can I use sliders to do interactive plots from a structure array?
이전 댓글 표시
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
Stijn Haenen
2020년 8월 4일
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
2020년 9월 17일
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
2020년 9월 17일
Rik
2020년 9월 17일
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!