Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7829201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:40:36+00:00 2026-06-02T10:40:36+00:00

I was encountered with usage of function eval(expression) in somebody else’s code in matlab:

  • 0

I was encountered with usage of function eval(expression) in somebody else’s code in matlab:
for example:

for n = 1 : 4
sn = int2str( n) ;
eval( [ 'saveas( fig'  sn  ', [ sName' sn ' ], ''fig'' ) ' ] );
end

MathWorks stuff in Matlab Help pointed out that:

Many common uses of the eval function are less efficient and are more difficult to read and debug than other MATLAB functions and language constructs.

After this, I find usage of this function in many other program languages, so as Python, JavaScript, PHP.

So I have a few questions:

  1. Will usage of this function be enfluenced on the performance of my code?
  2. If it will slow down execution, why does it occur?
  3. If it slow down execution every time when called, what reason for use this function in principle?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:40:38+00:00Added an answer on June 2, 2026 at 10:40 am
    1. Using eval here will certainly be slower than a non-eval version, but most likely it won’t be a bottleneck in you code. However, the performance is only one issue, maintenance (incl. debugging), as well as readability are other ones.
    2. The slowdown occurs because Matlab uses a JIT compiler, and eval lines cannot be optimized.
    3. Eval use is in most cases due to lack of knowledge about the Matlab functionality that would be appropriate instead. In this particular case, the issue is that the figure handles are stored in variable names called fig1 through fig4. If they had been stored in an array called fig, i.e. fig(1) etc, eval would have been unnecessary.

    EDIT Here are two excellent articles by Loren Shure about why eval should be avoided in Matlab. Evading eval, and More on eval.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I encountered something that I can't understand. I have this code: cout << f1
I decided to modify some code today, and encountered an error that doesn't make
Update: Edited code example to use AutoA for the workaround (which was the original
I was trying to understand c++0x std::bind and std::function usage in event handling /
I just encountered the following code (slightly simplified): /* periodically requests garbagecollect to improve
For example: <?php function get_current_user_id(){ static $id; if(!$id){ $id = 5; echo Id set.;
The following example demonstrates the problem I encountered in VC++ 2010: class Foo {
I encountered the following PL/SQL code(variables modified) at work: PROCEDURE test(i_w IN a.w%type,o_result IN
I encountered this regular expression that detects string literal of Unicode characters in JavaScript.
Encountered a frustrating problem in our application today which came down to an ArrayIndexOutOfBounds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.