Fields of Struct are not changing with functions
Show older comments
Hello, I am trying to create a uifigure that will contain two uisliders, one that will change the frame of the image dataset that is depicted on the figure, and a uislider that will control the max range.
The problem i am facing is that , even i am calling the app struct inside the functions and I am changing the fields of frame and max range, the actual app.frames still equals to 1, even though when using the uislider for the frames, I am changing the frames. The same applies to MaxSlider; in the figure the contrast is chaning but when checking the app.displayRange field, I get the initial value I gave.
function draft_app
load("appImage.mat")
app.Figure=uifigure('Name',"A Process Try towards Improvemnet");
app.ax=uiaxes(app.Figure,'Position',[5 50 550 400]);
% ------------- Initialize Values ---------------
app.images=images;
n=size(app.images,3)
app.frame=1;
app.cmin=min(app.images(:,:,n),[],'all');
app.cmax=max(app.images(:,:,n),[],'all');
app.displayRange=[app.cmin app.cmax];
colorbar(app.ax);
app.im=imshow(app.images(:,:,app.frame),app.displayRange,'Parent',app.ax);
colormap(app.ax, jet);
% ---------------- Check Update -------------
update2(app);
%%
n=size(app.images,3);
app.frameSlider=uislider(app.Figure,'Limits',[1 n],"Position",[50 120 300 3],'Value',1);
app.frameSlider.MajorTicks = 1:1:n; % Define major ticks at intervals of 1
app.frameSlider.MinorTicks = 1:1:n; % Define minor ticks at smaller intervals, if needed
app.frameSlider.ValueChangingFcn = @(src, event) updateAppFrames(app,event.Value);
%updateAppImage(object,number,min,max)
%
app.MaxSlider=uislider(app.Figure,'Limits',[1 app.cmax],"Position",[50 100 300 3],'Value',app.cmax);
app.MaxSlider.MajorTicks = []; % Define major ticks at intervals of 1
app.MaxSlider.MinorTicks = []; % Define minor ticks at smaller intervals, if needed
app.MaxSlider.ValueChangingFcn = @(src, event) updateAppMax(app,event.Value);
end
function updateAppMax(app,maximum)
app.cmax=maximum;
app.displayRange=[app.cmin app.cmax];
update2(app);
end
function update2(app)
set(app.ax,'CLim',app.displayRange);
fprintf('The range is %1.2f - %1.2f\n',app.displayRange(1),app.displayRange(2));
set(app.im,'CData',app.images(:,:,app.frame));
end
function updateAppFrames(app,frame)
app.frame=round(frame);
% app.cmin=min(app.images(:,:,app.frame),[],'all');
% app.cmax=max(app.images(:,:,app.frame),[],'all');
% app.displayRange=[app.cmin app.cmax];
update2(app);
end
Accepted Answer
More Answers (0)
Categories
Find more on Develop Apps Programmatically 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!