Help Eval will see Matlab with its own instructions
Eval Execute string with MATLAB expression. Eval (s), where S is a string, Caus
Es MATLAB to execute the string as an expression or statement.
The function of the Eval function is to convert a string to a MATLAB executable statement. In layman's terms, for example
You enter
A= ' b=1 ';
will see in Workspace. The type that generated the variable a,a is a string, and the contents of the string are B=1
And then you enter Eval (a)
You'll see that the variable b,b is a double matrix of 1 times 1, and the value of the element is 1.
In other words, executing eval (a) is equivalent to executing the content of a, equivalent to executing b=1
If a For statement can loop a number, then the eval combined with the for statement greatly increases its loop scope.
For example, you have to load some data, M1.mat,m2.mat, etc. until M100.mat
Ordinary young people may write programs like this
Load M1.mat
Load M2.mat
Then write 100 lines all the time, which is obviously too stupid. But the normal for statement cannot be completed
So the Eval function combines the for statement to reflect its value.
For i=1:100
eval ([' Load ' num2str (i) '. Mat '])
End
Only three lines are required.
In addition, Eval is also widely used in human-computer interaction, because Matlab's GUI, get command gets the character of the STR format
strings, which are typically converted to numbers by Str2Num, for subsequent processing. And if the STR string read into is
Cos,sin and the like. Then you need to combine the Eval function to convert the string to an instruction
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.