MATLAB examples not working

Hi,
I am very new to AMPL and MATLAB. I am having diffilculties running the matlab examples. I am trying to run “dietModel.m” example. I extracted a couple of lines from this example:

NUTR = {'A';  'B1';'B2';'C';'CAL';'NA'};
FOOD = {'BEEF' ; 'CHK'; 'FISH';'HAM';'MCH';'MTL';'SPG';'TUR'};
due = [60   10   15   20   295    938 ; 8   20   20    0   770   2180; 8   15   10   10   440    945;  40   25   10   40   430    278;  15   15   15   35   315   1182;  70   15   15   30   400    896;   25   25   15   50   370   1329; 60   15   10   20   450   1397];
df = DataFrame(2, 'NUTR', 'FOOD', 'amt');
df.setMatrix(transpose(due), NUTR, FOOD);

I get the following errors when running the above code:

179             if ismatrix(values) && size(values, 1) == 1 % row matrix
Unrecognized function or variable 'setMatrixPacked'.

Error in DataFrame/setMatrix (line 182)
            self.impl.setMatrixPacked(values, varargin);

Error in indexing (line 57)
                            builtin('subsref',obj,s);

I am using AMPL “option version ‘AMPL Version 20230124 (MSVC 19.29.30147.0, 64-bit)’” and MATLAB “R2022b Update 4 (9.13.0.2166757 - 64bit - win64)”.
I am currently not sure if the issue lies with AMPL examples or MATLAB.
Please can you advice that the AMPL examples work with my version of MATLAB?

Thanks
Gilles

1 Like

Hi @Gilles,

We are not being able to reproduce this issue. We have tested with MATLAB R2022b on Windows and macOS and in both cases the dietModel example and your snippet worked.

Could you please send us the output you get when you run setupOnce? The expected output is the following:

>> setupOnce

DYNAMIC JAVA PATH

<empty>

matlabbridgename =

    'matlab-lib.jar'

Using native binary at C:\ampl.mswin64\amplapi\matlab\..\bin\ampl-2.0.12.dll
Using api at C:\ampl.mswin64\amplapi\matlab\..\lib\ampl-java.jar
Using wrapper at C:\ampl.mswin64\amplapi\matlab
>> NUTR = {'A';  'B1';'B2';'C';'CAL';'NA'};
FOOD = {'BEEF' ; 'CHK'; 'FISH';'HAM';'MCH';'MTL';'SPG';'TUR'};
due = [60   10   15   20   295    938 ; 8   20   20    0   770   2180; 8   15   10   10   440    945;  40   25   10   40   430    278;  15   15   15   35   315   1182;  70   15   15   30   400    896;   25   25   15   50   370   1329; 60   15   10   20   450   1397];
df = DataFrame(2, 'NUTR', 'FOOD', 'amt');
df.setMatrix(transpose(due), NUTR, FOOD);
>> df

ans =

    NUTR         FOOD     |     amt    
    'A'           'BEEF'    |      60    
    'A'           'CHK'     |      8      
    'A'           'FISH'    |      8      
    'A'           'HAM'     |      40    
    'A'           'MCH'     |      15    
    'A'           'MTL'     |      70    
    'A'           'SPG'     |      25    
    'A'           'TUR'     |      60    
    'B1'          'BEEF'    |      10    
    'B1'          'CHK'     |      20    
    'B1'          'FISH'    |      15    
    'B1'          'HAM'     |      25    
    'B1'          'MCH'     |      15    
    'B1'          'MTL'     |      15    
    'B1'          'SPG'     |      25    
    'B1'          'TUR'     |      15    
    'B2'          'BEEF'    |      15    
    'B2'          'CHK'     |      20    
    'B2'          'FISH'    |      10    
    'B2'          'HAM'     |      10    
    'B2'          'MCH'     |      15    
    'B2'          'MTL'     |      15    
    'B2'          'SPG'     |      15    
    'B2'          'TUR'     |      10    
    'C'           'BEEF'    |      20    
    'C'           'CHK'     |      0      
    'C'           'FISH'    |      10    
    'C'           'HAM'     |      40    
    'C'           'MCH'     |      35    
    'C'           'MTL'     |      30    
    'C'           'SPG'     |      50    
    'C'           'TUR'     |      20    
   'CAL'          'BEEF'    |     295    
   'CAL'          'CHK'     |     770    
   'CAL'          'FISH'    |     440    
   'CAL'          'HAM'     |     430    
   'CAL'          'MCH'     |     315    
   'CAL'          'MTL'     |     400    
   'CAL'          'SPG'     |     370    
   'CAL'          'TUR'     |     450    
    'NA'          'BEEF'    |     938    
    'NA'          'CHK'     |     2180    
    'NA'          'FISH'    |     945    
    'NA'          'HAM'     |     278    
    'NA'          'MCH'     |     1182    
    'NA'          'MTL'     |     896    
    'NA'          'SPG'     |     1329    
    'NA'          'TUR'     |     1397

Hi,
Thanks for the advice above. It is working now that I run setupOnce.
Gilles

1 Like