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

  • Home
  • SEARCH
  • 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 8516065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:19:04+00:00 2026-06-11T05:19:04+00:00

So I have a for-loop in MATLAB, where either a vector x will be

  • 0

So I have a for-loop in MATLAB, where either a vector x will be put through one function, say, cos(x).^2, or a different choice, say, sin(x).^2 + 9.*x. The user will select which of those functions he wants to use before the for-loop.

My question is, I dont want the loop to check what the user selected on every iteration. Is there a way to use a pointer to a function, (user defined, or otherwise), that every iteration will use automatically?

This is inside a script by the way, not a function.

Thanks

  • 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-11T05:19:05+00:00Added an answer on June 11, 2026 at 5:19 am

    You can use function_handles. For your example (to run on all available functions using a loop):

    x = 1:10; % list of input values
    functionList = {@(x) cos(x).^2, @(x) sin(x).^2 + 9*x}; % function handle cell-array
    for i=1:length(functionList)
        functionOut{i} = functionList{i}(x); % output of each function to x
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a for loop in Matlab; inside it I am calling a function
Suppose I have a function y(t,x) = exp(-t)*sin(x) In Matlab, I define t =
I have a MATLAB routine with one rather obvious bottleneck. I've profiled the function,
I have an RGB image in MATLAB, and I want to loop through each
I have a loop $(.box).find('.video, .print, .web').closest('.box').each(function (index) { $(this).delay(100 * index).fadeIn(300); }); This
In Matlab, I have a loop that performs operations on arrays. I would like
I have a cell array in Matlab: strings = {'one', 'two', 'three'}; How can
I have noticed that matlab does some matrix function really fast for example adding
In MATLAB, I have a for loop which has a lot of interations to
It seems I have a MATLAB name clash with one of my variables called

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.