# Set 3-D matrix from matlab of size (MxNxP) that is effectively 2D (M=1, so it is 1xNxP)

**URL:** https://discuss.ampl.com/t/set-3-d-matrix-from-matlab-of-size-mxnxp-that-is-effectively-2d-m-1-so-it-is-1xnxp/614
**Category:** Support
**Tags:** matlab
**Created:** [June 18, 2023, 6:07pm UTC](https://discuss.ampl.com/t/set-3-d-matrix-from-matlab-of-size-mxnxp-that-is-effectively-2d-m-1-so-it-is-1xnxp/614 "2023-06-18T18:07:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Sarah\_O](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/sarah_o/32/321_2.png) [@Sarah\_O](https://discuss.ampl.com/u/Sarah_O)
#### Post date: [June 18, 2023, 6:07pm UTC](https://discuss.ampl.com/t/set-3-d-matrix-from-matlab-of-size-mxnxp-that-is-effectively-2d-m-1-so-it-is-1xnxp/614/1 "2023-06-18T18:07:13Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)
#### Post date: [July 19, 2023, 9:47am UTC](https://discuss.ampl.com/t/set-3-d-matrix-from-matlab-of-size-mxnxp-that-is-effectively-2d-m-1-so-it-is-1xnxp/614/2 "2023-07-19T09:47:12Z")

</div>

Hi @Sarah_O,

We have just released amplapi v2.1.4-20230719 with a fix for this bug.

```plaintext
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:

```auto
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.

```
