Hi,
I am working on a model where I need to run multiple scenarios with data generated in Matlab to set a 3-D matrix, below is a snippet of my code
U = 1:k;
dfP = DataFrame(3, ‘U’, ‘AP’, ‘W’, ‘Pr’);
dfP.setMatrix(Pr, U, AP, W);
dfP.toTable();
ampl.setData(dfP);
the setting works for different dimensions of Pr matrix, but when k=1, it generates the following error :
Error using DataFrame/setMatrix (line 182)
Java exception occurred:
java.lang.IllegalArgumentException: Argument is not an array
…
Error in DataFrame/subsref (line 57)
builtin(‘subsref’,obj,s);
Error in scenarios (line 85)
dfP.setMatrix(Pr, U, AP, W);
when on of the dimensions of a 3D matrix is e.g, matrix size is 1x8x4, it is effectively a 2D matrix (here 8x4). So does it not accept the case of where k=1.
Thank you for your help
1 Like
Hi @Sarah_O,
We have just released amplapi v2.1.4-20230719 with a fix for this bug.
k = 2;
U = num2cell(1:k);
AP = num2cell(1:8);
W = num2cell(1:4);
Pr = randn(k,8,4);
dfP = DataFrame(3, 'U', 'AP', 'W', 'Pr');
dfP.setMatrix(Pr, U, AP, W);
dfP.toTable()
k = 1;
U = num2cell(1:k);
AP = num2cell(1:8);
W = num2cell(1:4);
Pr = randn(k,8,4);
dfP = DataFrame(3, 'U', 'AP', 'W', 'Pr');
dfP.setMatrix(Pr, U, AP, W);
dfP.toTable()
produces the following output:
ans =
64×4 table
U AP W Pr
_____ _____ _____ ___________
{[1]} {[1]} {[1]} {[-0.8317]}
{[1]} {[1]} {[2]} {[-0.0186]}
{[1]} {[1]} {[3]} {[-0.2378]}
{[1]} {[1]} {[4]} {[ 0.2641]}
{[1]} {[2]} {[1]} {[ 0.6121]}
{[1]} {[2]} {[2]} {[ 0.4553]}
{[1]} {[2]} {[3]} {[ 0.8962]}
: : : :
{[2]} {[7]} {[2]} {[ 1.2856]}
{[2]} {[7]} {[3]} {[-0.8116]}
{[2]} {[7]} {[4]} {[-0.4938]}
{[2]} {[8]} {[1]} {[ 1.9313]}
{[2]} {[8]} {[2]} {[-0.2931]}
{[2]} {[8]} {[3]} {[-0.5167]}
{[2]} {[8]} {[4]} {[-0.7059]}
Display all 64 rows.
ans =
32×4 table
U AP W Pr
_____ _____ _____ ___________
{[1]} {[1]} {[1]} {[ 0.3450]}
{[1]} {[1]} {[2]} {[ 0.9601]}
{[1]} {[1]} {[3]} {[-0.7484]}
{[1]} {[1]} {[4]} {[-0.1448]}
{[1]} {[2]} {[1]} {[ 0.2864]}
{[1]} {[2]} {[2]} {[ 1.7319]}
{[1]} {[2]} {[3]} {[ 1.1230]}
: : : :
{[1]} {[7]} {[2]} {[ 0.1775]}
{[1]} {[7]} {[3]} {[-0.1754]}
{[1]} {[7]} {[4]} {[-0.7639]}
{[1]} {[8]} {[1]} {[ 0.2461]}
{[1]} {[8]} {[2]} {[-0.1237]}
{[1]} {[8]} {[3]} {[ 0.7092]}
{[1]} {[8]} {[4]} {[-1.1324]}
Display all 32 rows.