필터 지우기
필터 지우기

How to output command to command windows in the GUI CALLBACK?

조회 수: 1 (최근 30일)
MT_jsmith
MT_jsmith 2018년 10월 8일
편집: Stephen23 2018년 10월 8일
function plotdata_Callback(hObject, eventdata, handles)
% hObject handle to plotdata (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
evalin('base', 'plot(varString{2})');% code
The code can't plot a figure, I want to use workspace data to plot figure. Be equal to input plot(varString{2}); in the command windows.
  댓글 수: 1
Stephen23
Stephen23 2018년 10월 8일
편집: Stephen23 2018년 10월 8일
There are several things about this code that suggest a less-than-optimal design:
  • Using a callback to magically access data in the base workspace. Accessing data in another workspace not recommended, because it makes code slow, complex, and buggy (your question demonstrates this). A much better ("better" in the sense neater, more robust, much more efficient, less buggy) solution is to pass data to the GUI and process it within the GUI itself.
  • The variable name varString seems to suggest that you want to magically access variable names. Magically accessing variable names is one way that some beginners force themselves into writing slow, complex, buggy code that is hard to debug:
You would be much better off passing the data properly as input/output arguments, and processing it within the GUI.
See also your earlier question:

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by