필터 지우기
필터 지우기

public variable in gui

조회 수: 3 (최근 30일)
mohamed  al-asklany
mohamed al-asklany 2012년 4월 17일
hello,
how can i define variable all the function of gui see it?
[Merged information from duplicate question]
if i have tow func in gui and i have variable x i need x identified from function 1 and function 2
func 1
x=1+y;
func2
z=x+1

답변 (2개)

Image Analyst
Image Analyst 2012년 4월 17일
  댓글 수: 5
Walter Roberson
Walter Roberson 2012년 4월 18일
The FAQ gives examples for some of the solutions, and you can search the MATLAB documentation for information on the functions mentioned.
You can also ask specific questions about interpretation of the documentation.
Image Analyst
Image Analyst 2012년 4월 18일
What's so hard about adding your variable on to handles as a new member?

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


Walter Roberson
Walter Roberson 2012년 4월 18일
func 1
global x
x=1+y;
func 2
global x
z=x+1
This is not a recommended solution. The solutions in the FAQ that IA pointed you to are better ones.
  댓글 수: 5
Sean de Wolski
Sean de Wolski 2012년 4월 18일
global could be changed from somewhere completely different having nothing to do with the figure.
Walter Roberson
Walter Roberson 2012년 4월 18일
The theory goes that barriers to using a variable as if it is global will introduce reluctance to indeed use it as if it is global.
Using handles introduces notable barriers, such as needing to guidata() in the assigning routine to allow the change to be seen, and needing to guidata() in any calling routine that needs to know the updated value. And for cross-gui work, needing to know the figure number of the other gui in order to be able to access its information. It is common for people to run into difficulties when they do _not_ know these mechanisms, so in one sense the barriers are being effective.
On the other hand, I have the distinct impression that what newcomers tend to learn about handles is that there is a particular _pattern_ to use, and they just go ahead and use that pattern without understanding it. Sort of like people just going ahead and entering their password any time MS Windows or OS-X ask for it. Barriers that become treated by rote become ineffective barriers.

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by