MATLAB eval function usage

Source: Internet
Author: User

The function of eval_r () is to treat the strings in parentheses as statements and run them.

For example:Eval_r ('y1 = sin (2) ') is equivalent to inputting the Y1 = sin (2) command in the MATLAB command window.

You can operate on variables or files with rules for multiple names,

Example 1:

For x = 1:5

  Eval_r (['y', num2str (x), '=', num2str (x ^ 2), ';'])

End

The preceding statement is equivalent to executing the following five sentences:

 Ynum2str (1) = num2str (1 ^ 2 );

 Ynum2str (2) = num2str (2 ^ 2 );

 Ynum2str (3) = num2str (3 ^ 2 );

 Ynum2str (4) = num2str (4 ^ 2 );

 Ynum2str (5) = num2str (5 ^ 2 );

Example 2:

Subplot (711); plot (T, Y); Title ('original sign ');

For I = 1:6
   Subplot (7,1, I + 1 );
   Plot (T, IMF (I ,:));
   Eval_r (['title (''imf ', int2str (I), ''');']);
End

-------------------------

The above six lines of code actually execute the following seven commands:

Subplot (711); plot (T, Y); Title ('original sign ');

Subplot (7,1, 2); plot (T, IMF (1, :)); Title ('imf1 ');
Subplot (7,1, 3); plot (T, IMF (2, :)); Title ('imf2 ');
Subplot (7,1, 4); plot (T, IMF (3, :)); Title ('imf3 ');
Subplot (7,1, 5); plot (T, IMF (4, :)); Title ('imf1 ');
Subplot (7,1, 6); plot (T, IMF (5, :)); Title ('imf5 ');
Subplot (7,1, 7); plot (T, IMF (6, :)); Title ('imf6 ');

The last six statements are executed through the loop.

Here we use the e v a l () function to implement the output title ('imfi '); this statement

1. View title ('imf as a string

2. output the floating-point variable I (I =,) as a character.

3. Think of '); As a string

The above three parts are the output commands.Title ('imfi ');

It is worth noting that you want to output a single marker and replace it with '', just as the C language uses \ instead of \, which is a special symbol.

 References

Http://zhidao.baidu.com/question/122921390.html? Fr = ala0

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.