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

조회 수: 1 (최근 30일)
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);
imgf=imread(fullpathname);
if(size(imgf,3)>1)
imgf=rgb2gray(imgf);
end
imshow(imgf,'parent',app.UIAxes);
end
% Button pushed function: FilterTheImageButton
function FilterTheImageButtonPushed(app, event)
img=imgaussfilt(imgf); % I want to use "imgf" in here to filter the image
imshow(img,'parent',app.UIAxes);
end
end
  댓글 수: 2
Ali Zulfikaroglu
Ali Zulfikaroglu 2021년 3월 3일
I want to also use third button. In Third button I want to use roipoly command to draw a circle on image.
But I should use filtered image in second function and continue with that "img" in third button function .
mask=roipoly(img);
How will I draw a circle with using roipoly command on uıaxes ?
Rik
Rik 2021년 3월 3일
It doesn't look like roipoly allows the use of a uifigure, only a figure.

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2021년 3월 3일
Don't use global variables. There are many other ways to share data between callbacks. You should probably store the variable in a property.
  댓글 수: 4
Ali Zulfikaroglu
Ali Zulfikaroglu 2021년 3월 3일
I realised my mistake at property .
And it should be added app.
properties (Access = private)
t % Using this description
end
% 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);
imgf=imread(fullpathname);
if(size(imgf,3)>1)
imgf=rgb2gray(imgf);
end
imshow(imgf,'parent',app.UIAxes);
app.t=imgf % t is in here property function and it should be app.t
end
% Button pushed function: FilterTheImageButton
function FilterTheImageButtonPushed(app, event)
img=imgaussfilt(app.t);
imshow(img,'parent',app.UIAxes);
end
end
Rik
Rik 2021년 3월 3일
Yes, that is equivalent to what I suggested. Now you can remove that global imgf; line.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by