필터 지우기
필터 지우기

struct and getfield variable value

조회 수: 1 (최근 30일)
Vincent I
Vincent I 2013년 6월 5일
Hi, I'm trying to get the value that's in the variable but I can only get to the name of the variable and not the actual value. Thank you
w = getfield(evalin('base','whos'),{13,1},'name')
w = Variable

답변 (2개)

Image Analyst
Image Analyst 2013년 6월 5일
What workspace are you trying to import this variable (that lives in the base workspace) into? The workspace of one of your functions? How did a variable get into the base workspace anyway? Did you run a script and it left the variable in the base workspace, and now you're running a function, which has its own local workspace, and now you want to import the variable that your script left in the base workspace into the workspace of your function? If what I said totally confused you then you need to read up on workspaces. Also, look at the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
  댓글 수: 1
Vincent I
Vincent I 2013년 6월 5일
편집: Vincent I 2013년 6월 5일
yes, I left the workspace. I'm running in a different function and I'm trying to access the base ws where the variable was saved and get its value.
nvm.... its been a long day
evalin('base','variable')
no need for w = getfield(evalin('base','whos'),{13,1},'name')

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


Jan
Jan 2013년 6월 5일
Trying to transport variables magically remote controlled is obviously a bad idea. Although it might work, I recommend not to do this:
w = getfield(evalin('base','whos'), {13,1}, 'name')
value = evalin('base', w)
Brrr. You would suffer.
  댓글 수: 2
Vincent I
Vincent I 2013년 6월 6일
Sounds good Thank you
Daniel Shub
Daniel Shub 2013년 6월 6일
Did you miss the part where Jan said I recommend not to do this

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

카테고리

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