Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to define the input variable for different functions with same format

Subject: how to define the input variable for different functions with same format

From: lily

Date: 26 Sep, 2010 07:37:07

Message: 1 of 1

Now I write a multi-objective PSO code, but I don't know how to define the input variable for different objective functions, the main code of MOPSO as follows,

for nNfs=1:Nfs % Nfs--number of objective functions.
    f2eval=f2evalstr{nNfs}; % f2eval--objective function to evalue, string array.
    fs=feval(f2eval,inputdata); % run the objective function 'f2eval' to get fitness.
    fits(:,nNfs)=fs;
end

Cause different objective functions with different input variables, and in order to keep the format unchanged, now I define the inputdata as a struct array. But this method makes the inputdata have too many fields, which would cause the code not easy to modify. The inputdata may be changed after run code 'fs=feval(f2eval,inputdata)', and I want to change some fields of inputdata. So my question is how to define the inputdata will make the code more enforceable? Or the main code structure should be changed, or should decompose it into multi-blocks?

Any suggestion is appreciated.Thanks in advance.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us