MATLAB Answers

How to use First button function codes "symbol name" in Second button function in App Designer

1 view (last 30 days)
Ali Zulfikaroglu
Ali Zulfikaroglu on 3 Mar 2021
Commented: Rik on 3 Mar 2021
I have an image. In app designer , I use "axes application" to add image there. When I click first button I add image and show it in Axes area.
I added second button . In second button I want to filter that same image when I click it.
For example my image name is "imgf" and I use imshow(img) when I click first button and show it. I want to use that "imgf" in my second button. But it gives error.
Because that "imgf" belongs to in first button function codes. How will I use that "imgf" in my second button function codes.
Codes are below
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: SelectAnImageButton
function SelectAnImageButtonPushed(app, event)
global imgf;
[filename pathname]= uigetfile({'*.jpg'},"Open file");
fullpathname= strcat(pathname,filename);
% Button pushed function: FilterTheImageButton
function FilterTheImageButtonPushed(app, event)
img=imgaussfilt(imgf); % I want to use "imgf" in here to filter the image

Sign in to comment.

Accepted Answer

Rik on 3 Mar 2021
Don't use global variables. There are many other ways to share data between callbacks. You should probably store the variable in a property.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!