Variable evaluated with "evalin" vanishes
이전 댓글 표시
Hello everyone, I just received Matlab 2014b after working with 2012a and I tried to run my „old“ scripts. Now the problem I encountered was the following: I store some data x using assignin to the ‘base’ workspace. I created a GUI (with guide) which is supposed to (among others) plot the data x in an axis. This is the part of the code which should (and in 2012a DID) plot the data:
function Show_path_CreateFcn(hObject, eventdata, handles)
% hObject handle to Show_path (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
data_laser = evalin('base', 'ld');
plot(data_laser(:,3));
Now here is the strange part: It reads the data from the workspace (I know because when I leave out the semicolon, all numbers are “written out” in the command window) but the plot-function returns an error, telling me that my variable “data_laser” doesn’t exist. Can somebody help me here? Thank you in advance!
댓글 수: 3
Rich Ohman
2015년 3월 19일
Can you provide the exact error message? Is it possible that the base workspace variable is being cleared?
Stephen23
2015년 3월 23일
Avoid using evalin and eval for passing variables like this. Use guidata or the handles structure instead and you will avoid this problem altogether.
CrazyEngineer
2015년 3월 23일
채택된 답변
추가 답변 (1개)
Image Analyst
2015년 3월 18일
0 개 추천
OK, good. It's a blessing in disguise. Now you can program it up properly without using functions like evalin(), assignin(), and eval(). See the FAQ for better methods: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
댓글 수: 4
CrazyEngineer
2015년 3월 18일
Image Analyst
2015년 3월 19일
Probably. But are you sure that "ld" is still in the base workspace? How can you see the base workspace? When you're in the debugger you can only see the local workspace of the specific function that you're in.
What is the difference between your GUI and your main script? Is it all in one m-file that you're using GUIDE with? Or do you have a GUI m-file (either a script or a GUIDE-built function) and a separate "main script" m-file?
CrazyEngineer
2015년 3월 23일
Guillaume
2015년 3월 23일
@Image Analyst, totally agree with using a better method of sharing data between gui and main code. I just want to correct something:
When you're in the debugger you can only see the local workspace of the specific function that you're in
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!