필터 지우기
필터 지우기

GUI register?

조회 수: 1 (최근 30일)
Kyle
Kyle 2011년 7월 9일
Hi,
I'm wandering how come the below code from GUI doesnt create registers that are stored in workplace? What should i do if i wana create the register in workplace via GUI?
function im1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to im1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
[FileName,PathName]= uigetfile(...
{'*.bmp;*.jpg;*.jpeg;*.tif;*.tiff;*.png','All Image Files(*.bmp,*.jpg,*.jpeg,*.tif,*.tiff,*.png)';...
'*bmp','bitmap Files (*.bmp)';...
'*.jpg;*.jpeg','JPEG Files(*.jpg,*.jpeg)';...
'*.tif;*.tiff','Tiff Files(*.tif,*.tiff)';...
'*png','PNG Files (*.png)';...
'*.*','All Files (*.*)'}, ...
'Pick an image file');
fullpath = sprintf('%s%s',PathName, FileName);
a=imread(fullpath);
imshow(fullpath,'parent',handles.im1);
  댓글 수: 4
Kyle
Kyle 2011년 7월 10일
ya i'm talking about variable. i notice that the variable a is not in my workspace after executing the code.
a=imread(fullpath);
This line was added later on, as i want to store the image in variable a so that other function could use it. now the only way i could pass the variable is by making it 'global' on every function that need to use variable a.
Image Analyst
Image Analyst 2011년 7월 10일
Yes, that is true. It is more like a "friend" or shared variable than a true global. It's not really global, only routines that have the line "global a;" will be able to see it. It's saved in the global workspace of your m-file so you won't see it in the "base" workspace which is always there, even when your code finishes. If you need it in the base workspace (for some reason that I can't figure out) then you need to call assignin, as the others said.

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

채택된 답변

Prabhakar
Prabhakar 2011년 7월 10일
If the question means that you want to create a variable in the base workspace filled with data from the GUI. Then in a callback for a button, use the ASSIGNIN function with an argument for assignment into the 'base' workspace to create variables in the base workspace with data from the GUI.
Refer to the documentation for ASSIGNIN at the following link: http://www.mathworks.com/help/matlab/ref/assignin.html

추가 답변 (1개)

Paulo Silva
Paulo Silva 2011년 7월 10일
Like Prabhakar said use assignin
a=imread(fullpath);
assignin('base','a',a);
  댓글 수: 1
Kyle
Kyle 2011년 7월 10일
Thanks.

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

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by