Reading in and Evaluating strings from standalone GUI using appdata
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Robert Cumming
am 30 Okt. 2012
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
am 30 Okt. 2012
1 Kommentar
Robert Cumming
am 1 Nov. 2012
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.
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!