Reading in and Evaluating strings from standalone GUI using appdata
조회 수: 4 (최근 30일)
이전 댓글 표시
I have been attempting to write a standalone windows GUI for a program that I have. It necessitates that I allow the user to input a string function for a number of items and at some point in the code it executes said strings. The final value of the strings are a function of an array (T) and output an array [item name](j). There is already a string value stored in appdata with the same name (a default in case no user changes are made).
For example.
Default written into program:
setappdata(0,'Item1' , '50.^(-7590/T(j)-7.46)');
In user window, a box with a custom entry such as:
50.^(-150/T(j)+1) and a corresponding GUI code for
setappdata(0,'Item1',get(handles.edit107,'string'));
where the tag of the text box is edit107
and a subsequent evaluation of
Item1result(j)=eval(getappdata(0,'Item1'));
Assuming the T and j are both defined properly as arrays.
In the certain situation where a user might enter just a single number (which is realistic).
Is there anyway around the:
Undefined function 'eval' for input arguments of type 'double'.
댓글 수: 0
답변 (2개)
Robert Cumming
2012년 10월 30일
Am I correct in assuming the user enters any string which then gets executed in eval? This is NOT advisable.... for example: the user could enter: 'system ( 'delete C:\*' )'
Anyway - to answer your questions: have you seen
try
do something
catch % if it errors - the error is captured
do something else
end
Matthew
2012년 10월 30일
댓글 수: 1
Robert Cumming
2012년 11월 1일
You should add this to your original question - since it builds on your question - but yes isnumeric is a satisfactory way of checking if a variable is a number.
Perhaps if you expalin your aim in more detail you might get more help on avoiding eval.
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!