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 7727237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:24:35+00:00 2026-06-01T05:24:35+00:00

Hello I am new to MATLAB , I wanted to know how can I

  • 0

Hello I am new to MATLAB , I wanted to know how can I make my string into function . I want to access the function as a string from user in standard Matlab format (e.g exp(-10*X)-sin(pi*X)-2*tanh(X) ) Here X is the variable. Then I want to replace ‘X’ with ‘low’ and ‘high’ variables to calculate value of function at these limits. I have used ‘strrep’ for this purpose. I am getting the following errors
1)Undefined function or variable ‘X’.
2) I cannot see whether ‘X’ was replaced with ‘low’ and ‘high’.

Any help will be truly appreciated.
Below is my code.

    high=input('Upper Limit of the Interval : ');

    low=input('\nLower Limit of the interval : ');

    usr_funct=input('Enter The Function in standard Matlab Format.\nEnter "X" for the
    variable and * for multiply \n');    % Example exp(-10*X)-sin(pi*X)-2*tanh(X);

    middle = (low+high)/2;

    Flow =strrep(usr_funct, 'X', 'low');
    Fhigh =strrep(usr_funct, 'X', 'high');

   sprintf('Flow '); % This was to check if 'X' was replaced with 'low'. It is not printing anything
  • 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-01T05:24:37+00:00Added an answer on June 1, 2026 at 5:24 am

    I think that you are looking for the eval function. That will evaluate a string as matlab code.

    Here is an example:

    str = 'exp(-10*X)-sin(pi*X)-2*tanh(X)' ; % let str be your math expression
    high = 10; % Ask the user
    low = -5; % Ask the user
    
    % Now we evaluate for High and Low
    X = low; % We want to evaluate for low
    ResultLow = eval(str); % That will return your value for X = low
    X = high; % We want to evaluate for low
    ResultHigh = eval(str); % That will return your value for X = high
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello am new with mongoengine. I just want to retrieving an image from mongoengine
Hello I`m new with C# and I want to make a simple C# pin
Hello I'm new to Joomla and I want to change the way an account
hello I'm new to PHP programming and I migrated from ASP .net to PHP..
I want to add new function extra to library class (orig for example). orig.extra(rich.Arg())
Hello am new to array can someone help? i have array in array. how
I am trying to migrate over to Python from Matlab and can't figure out
hello im new and learning javascript. I'm trying to make a program of addition
Hello iam new to GWT framework. I want to persist my domain objects/entities to
I make a alternate entry point that display a dialog Hello new week on

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.