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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:13:40+00:00 2026-06-11T02:13:40+00:00

My Matlab program has multiple inputs as a struct ( in.a , in.b ,

  • 0

My Matlab program has multiple inputs as a struct (in.a, in.b, etc.)
and multiple outputs (out.a, out.b, etc.)

I would like to use the genetic algorithm solver from teh optimization toolbox to find the best input in.a, while all the other inputs are constant. The fitness is one of the outputs, e.g. out.b(2,3).

How do I “tell” the solver this?

Thanks
Daniel

  • 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-11T02:13:41+00:00Added an answer on June 11, 2026 at 2:13 am

    It is not uncommon in programming to have a situation where what is most convenient for your function and what some library call expects of it don’t agree. The normal resolution to such a problem is to write a small layer in between that allows the two to talk; an interface.

    From help ga:

    X = GA(FITNESSFCN,NVARS) finds a local unconstrained minimum X to the
    FITNESSFCN using GA. […] FITNESSFCN accepts a vector X of size
    1-by-NVARS, and returns a scalar evaluated at X.

    So, ga expects vector input, scalar output, whereas you have a structure going in and out. You would have to write the following (sub)function:

    function Y = wrapper_Objfun(X, in)
        in.a = X; %# variable being optimized
        out  = YOUR_REAL_FUNCTION(in); %# call to your actual function
        Y    = out.b(2,3); %# objective value
    end
    

    and then the call to ga will look like

    X = ga(@(x) wrapper_Objfun(x,in), N);
    

    where N is however large in.a should be.

    Also have a read about it in Matlab’s own documentation on the subject.

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

Sidebar

Related Questions

I have a Matlab program that is running longer than I'd like it to.
I've written an image processing program in MATLAB which makes heavy use of the
I have know that the ode45 solver has adaptive step size controlled by Matlab
I would like to take two images and convolve them together in Matlab using
I have a MATLAB program that graphs some things and then outputs the graph
I have a Matlab program that generates a list x = 6.1692 8.1863 5.8092
I am writing a Matlab program for simpson's rule I keep getting an error
I am going to run a Matlab program in a remote Linux server using
In a pylab program (which could probably be a matlab program as well) I
Is there any way to output/display information from a MATLAB program without an ending

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.