Attempt to reference field of non-structure array

2 views (last 30 days)
Hi, I'm trying to use a matlab toolkit with LSSVM and i've been doing multiple output regression. During the tunelssvm command i'm getting this error.
the input is a 3000x6 matrix the output is a 3000x3 matrix
Attempt to reference field of non-structure array.
Error in tunelssvm (line 145) if model.code(1) == 'c', % changed

Accepted Answer

Walter Roberson
Walter Roberson on 26 Jan 2016
That appears to be a bug in the tunelssvm code near lines 128 to 143.
If you look at https://github.com/stablum/nn/blob/master/Assignment4/LSSVMlabv1_8/tunelssvm.m then although that is not the master version of the code, it appears to be the same as the code that you can download from http://www.esat.kuleuven.be/sista/lssvmlab/
Look near line 4 to 15 and compare to lines 32 to 40, and you can see that there are two different ways of calling the routine, one of which returns a numeric value as the first output and the other of which returns a model as its first output. Now look at lines 60 to 65 and see that if the routine is called with a cell array as its first parameter then func=1 is set and a model is constructed from the cell. Now look at lines 127 to 137 and you can see that if multiple dimensions are requested then the routine calls itself recursively passing its parameters in cell array form, which is the request to get back numeric values in the first parameter. It stores those numeric values into gamt and after stores model.gam = gamt, thus replacing whatever model.gam it might have had with those numeric values. Then at line 139 to 143, if func is true then model = model.gam which replaces the model with those numeric values it just calculated; func is true if the routine was originally called in cell array form. And then at line 145 it tries to test model.code(1), but model has been replaced by numeric values so the program fails.
The work-around for this bug is to not call it in cell array form if you have multiple output dimensions; then func would be 0 from lines 60 to 65 and model would not be replaced with model.gam . What to do instead? Call initlssvm() to construct the model object and pass that in, and expect the call to tunelssvm to return a struct in which the 'gam' field is what you would have received as the first output with the way you were calling it before.

More Answers (1)

Image Analyst
Image Analyst on 26 Jan 2016
the variable model is not a structure. Put this line before that line
whos model
What does it say in the command window?
  1 Comment
Jarev Divinagracia
Jarev Divinagracia on 26 Jan 2016
Hi,
If i place it before line 145
this comes out:
Name Size Bytes Class Attributes
model 1x3 24 double

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!