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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:21:12+00:00 2026-06-04T03:21:12+00:00

I use anonymous functions for simple data value transforms. The anonymous functions are defined

  • 0

I use anonymous functions for simple data value transforms. The anonymous functions are defined with the following syntax

sqr = @(x) x.^2;

I would like to have a simple anonymous function that returns more than one output that can be used as follows . . .

[b,a] = myAnonymousFunc(x);

The Matlab documentation suggests that this is possible, but it does not give an example of the syntax needed to define such a function.

http://www.mathworks.co.uk/help/techdoc/matlab_prog/f4-70115.html#f4-71162

What is the syntax to define such a function [in a single line, like the code example at the top of my post]?

  • 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-04T03:21:13+00:00Added an answer on June 4, 2026 at 3:21 am

    Does this do what you need?

    >> f = @(x)deal(x.^2,x.^3);
    >> [a,b]=f(3)
    a =
         9
    b =
        27
    

    With this example, you need to ensure that you only call f with exactly two output arguments, otherwise it will error.

    EDIT

    At least with recent versions of MATLAB, you can return only some of the output arguments using the ~ syntax:

    >> [a,~]=f(3)
    a =
         9
    >> [~,b]=f(3)
    b =
        27
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use LINQ to solve the following problem, I have the
Anonymous functions are available from PHP 5.3 . Should I use them or avoid
What are the best use cases for anonymous types? It would seem to me
I am trying to use Expression Trees and anonymous types to achieve the following.
How can I get output from Java anonymous classes? In .Net I would use
I have a simple ajax call like this: $.ajax({ url: u, type: POST, dataType:
After discovering lambda expressions, and their use as anonymous functions, I've found myself writing
Can functions be stored as anonymous functions directly in column as its value? Let's
How can I use PHP closure function like function() use() on PHP 5.2 version
I use anonymous functions for diagnostic printing when debugging in MATLAB. E.g., debug_disp =

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.