Hi,
I want to create a control that is handling my figures. I will put down a minimal example here. My main problem is how to change a class property (m_CurFigureIndex), when executing a callback function.
So the main routine is:
close all;figure('name','F1')figure('name','F2')figure('name','F3')FC = C_MinFigureControl;FC = FC.ActivateEventControls;
And my class definition:
classdef C_MinFigureControl properties m_FigureHandle m_CurFigureIndex end methods (Access = public) function obj = C_MinFigureControl obj.m_CurFigureIndex = 1; obj = obj.GetAllFigH; figure(obj.m_FigureHandle(obj.m_CurFigureIndex)) end % function C_MinFigureControl
function obj = GetAllFigH(obj) obj.m_FigureHandle = findobj('Type','figure'); if ~isempty(obj.m_FigureHandle) [~, ind] = sort([obj.m_FigureHandle.Number]); obj.m_FigureHandle = obj.m_FigureHandle(ind); end % if not empty
end % function GetAllFigH
function obj = Scroll(obj, ScrollCount) obj.m_CurFigureIndex = obj.m_CurFigureIndex + ScrollCount; obj.m_CurFigureIndex = max(obj.m_CurFigureIndex,1); obj.m_CurFigureIndex = min(obj.m_CurFigureIndex,length(obj.m_FigureHandle)); figure(obj.m_FigureHandle(obj.m_CurFigureIndex)) end % function Scroll
function obj = ActivateEventControls(obj) set(obj.m_FigureHandle,'WindowScrollWheelFcn',@obj.FigScroll); end % function ActivateEventControls
function FigScroll(obj,src,CallBackData) ScrollCount = 0; if strcmp(CallBackData.EventName,'WindowScrollWheel') ScrollCount = CallBackData.VerticalScrollCount; end % if CallBackData
obj = obj.Scroll(ScrollCount); end endend
So I am getting all figure handles and then create a callback function for scrolling with the mousewheel (FigScroll). I wanna change m_CurFigureIndex on each scroll to keep track of the current figure. This one does not work, I do not know how to pass back the value, so that the real class does change. Appears there is always just the copy changing. So next scroll event I am always back to m_CurFigureIndex = 1.
I would appreciate any hint for a fix or a hint what a more proper way of coding this is.
Thank you in advance Sven
Best Answer