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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:30:35+00:00 2026-06-14T19:30:35+00:00

Say that I have a function foo defined as [a b] = foo(c ).

  • 0

Say that I have a function foo defined as

   [a b] = foo(c ).

If I consider a function handle

 f = @(c)foo(c)

to be used e.g. in a cellfun call, what I get is an f behaving equivalently to a foo defined like

  a = foo(c)

i.e., the returned value b gets lost.

Therefore, when such an f is put in a cellfun call, the output cell will have just the as and will miss the bs (which I currently care about). Visually

    cellfun(f,input)

  [a(input{1})]           ?
  [a(input{2})]           ?
     ....            b gets killed along the way

Question: how to define a function handle to foo which catches just the bs? i.e. giving a behavior analogous to a definition of foo like

  b = foo(c)

i.e.^2, wasting the as.

Moreover, is it possible to (efficiently) catch both a and b in a unique cellfun call?

  • 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-14T19:30:36+00:00Added an answer on June 14, 2026 at 7:30 pm

    From the documentation of cellfun:

    [A1,…,Am] = cellfun(func,C1,…,Cn) calls the function specified by function handle func and passes elements from cell arrays C1,…,Cn, where n is the number of inputs to function func. Output arrays A1,…,Am, where m is the number of outputs from function func, contain the combined outputs from the function calls.

    So yes, cellfun can use a multi-output function and in this case it simply returns a number of outputs. If you want to use the second one only, you can use ~ to ignore the first one. The same goes for multiple outputs of anonymous functions – they will be returned if you specify multiple output arguments. Here is a simple code:

    function test
        x{1} = 1;
        x{2} = 2;
        [~, B] = cellfun(@foo, x);
        f=@(c)foo(c);
        [A, B] = f(1);
    
        function [a b] = foo(x)
            a = x+1;
            b = x+2;
        end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a function foo that I want to call n times. In
Let's say that I have an Erlang function, with spec. -spec foo(integer(), string()) ->
Let say, that i have defined the same function for windows and mac, with
Say I have a Javascript class defined and instantiated like this: Demo = function()
Ok, so let's say I have a type defined like so: type Foo =
Many people have argued about function size. They say that functions in general should
Say I have a function that does the following in Vb.net For i as
Say I have a function that takes an arbitrary number of arguments (the last
Say I have a function func(i) that creates an object for an integer i,
I have a function that updates several tables. As an example, let's say it

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.