How to fix axis of plot while using callback for slider?
Show older comments
How do I fix the axis so they don't autoscale when using the slider I created? I have had a lot of problems getting the slider to work. By using set at the end, the slider updates the plot fluently though the code is not pretty. I know that I, in the set command, create the new plot to be displayed when moving the slider, but i can't seem to control either axis, legends nor title of the plot in the set command.
if true
% Create figure for containing the plots
f = figure;
% Rescale the traces
a = (max(x(z).data_A) ./ max(x(z).data_C));
b = (max(x(r).data_A(1:140)) ./ max(x(r).data_B(1:140)));
AB = x(y).data_A;
B = (x(y).data_B ./ (1 ./b));
A = (x(y).data_C ./ (1 ./a));
% Create room on the figure for the slider
ax = axes('Parent', f, 'position', [0.13 0.39 0.77 0.54]);
% The plot containing the pulses
plot(steps, AB, 'b', steps, B, 'r', steps, A,'k');
axis([1 200 -0.0015 0.0015]);
legend('AB','A','B')
title('Visual of pulses')
% Creating the slider
h = uicontrol('Parent',f,...
'Style','slider',...
'Position',[81,54,419,23],...
'value',y,...
'min',1,...
'max',M,...
'Callback', @sliderCallback);
bgcolor = f.Color;
hl1 = uicontrol('Parent',f,'Style','text','Position',[50,54,23,23],...
'String','1','BackgroundColor',bgcolor);
hl2 = uicontrol('Parent',f,'Style','text','Position',[500,54,23,23],...
'String',M,'BackgroundColor',bgcolor);
hl3 = uicontrol('Parent',f,'Style','text','Position',[240,25,100,23],...
'String','Trace','BackgroundColor',bgcolor);
set(h,'Callback',@(a,b) plot(steps, x(round(get(a,'Value'))).data_A,'b',...
steps,(x(round(get(a,'Value'))).data_B./(1./(max(x(r).data_A(1:140))./max(x(r).data_B(1:140))))),'r',...
steps, (x(round(get(a,'Value'))).data_C./(1./(max(x(z).data_A) ./ max(x(z).data_C)))),'k'))
end
Any tips would be much appreciated. Running MATLAB R2015b.
Answers (0)
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!