Attempt to refrence field of non structured array

Hello,
I am new to MATLAB and I am trying to use the MOGA tool for optimization. When I run the optimization I get the following error
??? Attempt to reference field of non-structure array.
Error in ==> gamultiobjsolve at 28
state.Generation = state.Generation + 1;
Error in ==> gamultiobj at 240
[x,fval,exitFlag,output,population,scores] = gamultiobjsolve(FitnessFcn,nvars, ...
It would be great if you could help me out.

Answers (1)

Please post how you call the function. It seems like the varaible "state" should be a struct, but it has another type.
A general method to identify such problems is using the debugger:
dbstop if error
Then start the program again and Matlab stops, when the error occurres. Now you can inspect the calling tree and the values of the locally used variables.

3 Comments

Thank you for helping me out Jan. there are two m-files. the output of one is taken as the input for the other. the code for optimization is
function y = test2(x)
y=zeros([1 4]);
f=funVAMPzero;
a=f.a;
y(1)=a(1);
y(2)=a(2);
y(3)=a(3);
y(4)=a(4);
end
When i use the MOGA tool for this i get the error.
I do neither know the MOGA tool, nor can I guess what "use for" means in this case. Did you try to debug your code already? You know, debugging is a very important tool for creating programs and it has much more power than a forum.
Thanks for ur help... I will try to do tat...

This question is closed.

Asked:

on 12 Nov 2012

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!