Reading in and Evaluating strings from standalone GUI using appdata
1 次查看(过去 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 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!