필터 지우기
필터 지우기

Accessing a function from GUI1 in GUI2

조회 수: 1 (최근 30일)
Jason
Jason 2018년 2월 6일
댓글: Jason 2018년 2월 7일
How can I call a function in GUI1 called Autoscaleimage from GUI2? (Created by GUIDE).
function [high,low]=Autoscaleimage(handles,Image,n)
mn=mean(Image(:));
sd=std2(Image(:));
low=mn-sd;
high=mn+n*sd;
  댓글 수: 3
Adam
Adam 2018년 2월 7일
Pass in the image handle directly from your GUI. It is always a good idea to keep hold of the handles of the things you plot, e.g.
hImage = imagesc( ... )
Jason
Jason 2018년 2월 7일
Thanks

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

채택된 답변

Jan
Jan 2018년 2월 6일
What does "a function in GUI1 called Autoscaleimage" exactly mean? Is this a subfunction in the M-file GUI1.m? Then it might be easy to move this function to an own M-file. Then it can be used from all other functions.
The input handles is not used inside this function. Then it would be cleaner to omit it.
  댓글 수: 8
Adam
Adam 2018년 2월 6일
You should never be wanting to pass the handles of one GUI to a standalone function when you can get away with it. I have done it on occasion, for specific purposes, when I wanted to create a system of button highlighting and enabling/disabling based on the state of an underlying program where passing all the ui controls to such a function would just be silly, but in general a handles structure should remain within its GUI, it has no business being outside it and can create all manner of bugs that you really don't want.
If you want the same functionality from two different GUIs you should extract the relevant parameters from the handles structures of one or other GUI so the common interface of the function needs to have no knowledge of a massive handles struct that comes with extraneous UI controls and goodness knows what else attached to it.
Jason
Jason 2018년 2월 6일
OK thankyou for your comments - I get the message and will try to adapt my code as you suggest.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by