필터 지우기
필터 지우기

Convert lokal variables in to Global varibles.

조회 수: 4 (최근 30일)
cemsi888
cemsi888 2015년 3월 9일
댓글: cemsi888 2015년 3월 10일
i am using gui now in my Project. In order to see some results and use in further pushbuttons i used assignin .However when i want to use These structure Array which i created and made visisble by using assignin,i can not use it unfortunately. do you know any idea haw can i convert local variables in to global variables

답변 (2개)

Jan
Jan 2015년 3월 9일
By the way: Using assignin and global variables are bad programming practice. Try to avoid it and store the variables in the GUIs ApplicationData, e.g. by the guidata command. Search in this forum for "assignin" to get more opinions to this topic.
  댓글 수: 5
Stephen23
Stephen23 2015년 3월 9일
편집: Stephen23 2015년 3월 9일
This need to use assignin is apparently common with German MATLAB users: I'm fascinated by the peculiar differences between question in goMatlab and MATLAB Answers: While the majority of German speaking beginners seem to transfer variables to functions by ASSIGNIN and EVALIN (and suffer from the resulting difficulties), this does rarely appear here
Quote from Jan Simon:
@cemsi888: Learn to avoid assignin , those variables already have their own workspace, they don't need to be in the base workspace too! Use the debugging tools if you want to have a look at them while you are writing your code.
@Jan Simon: any idea on the origin of this cultural difference?
cemsi888
cemsi888 2015년 3월 10일
@ Adam i created structurearray which Name is Info. It contains Information about pfad file Name etc. My target is after i choose and read the article i want to see which file did i choose where can i this file find etc.. Yes you are right..In german matlabforums they generally advice to use assiginin and evalin...

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


Stephen23
Stephen23 2015년 3월 9일
편집: Stephen23 2015년 3월 9일
Read the documentation for global. It has examples too, like this one:
function setGlobalx(val)
global x
x = val;
and
function r = getGlobalx
global x
r = x;
which you can use to store a value, and retrieve it later using, even from a different workspace.
  댓글 수: 1
Image Analyst
Image Analyst 2015년 3월 9일
And read the FAQ too. http://matlab.wikia.com/wiki/FAQ#Are_global_variables_bad.3F If you're careful you can use globals without problem. Of course if you do dumb things in a function like assign a variable that you shouldn't have, then outside of that function the bad value will be seen regardless if you assigned it to a global variable or used setappdata()/getappdata() to assign/retrieve it.

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by