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!