cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
MFVIT
Level IV

Run Matlab simulations and create a JMP data table with simulations results

Dear All,

I am using JMP to run #Matlab simulations. I created a design with JMP that has three factors (par1, par2 and par3) and several empty columns for the responses (y1, y2). I created a JSL scripts that for each row of the design runs the Matlab code and gets the results of the simulation (three vectors: time, y1 and y2; y1 and y2 are in fact functions of time). Now I would like to create a JMP data table with par1, par2, par3, time, y1 and y2. Of course, for a given simulations par1, par2 and par3 have to have the same values repeated along the simulation. Here is an example of the new table that I would like to create. Can anyone tell me how I should approach the JSL code for that once I have imported time, y1 and y2 as columns into JMP?

Many thanks.

 

par1       par2       par3       time      y1           y2

3             1             1              1             ..             ..

3             1             1              2             ..             ..

3             1             1              3             ..             ..

4             1             1              1             ..             ..

4             1             1              2             ..             ..

4             1             1              3             ..             ..

1 ACCEPTED SOLUTION

Accepted Solutions
MFVIT
Level IV

Re: Run Matlab simulations and create a JMP data table with simulations results

Thank you very much for your help. Based on your suggestions I was able to write a jsl code that solved my problem. Here is the code. 

 

 

MATLAB Submit( "iii=0;" ); // Initialize the counter in Matlab

For Each Row(
    dt1, 

    row_n_dt1 = row_n_dt1 + 1;

    v0 = :Pattern[row_n_dt1];
    v1 = :F1[row_n_dt1];
    v2 = :F2[row_n_dt1];
    v3 = :F3[row_n_dt1];
    MATLAB Submit( "iii=iii+1;" );

    MATLAB Send( v1 );
    MATLAB Send( v2 );
    MATLAB Send( v3 );

    MATLAB Submit( "FF1=v1" );
    MATLAB Submit( "FF2=v2" );
    MATLAB Submit( "FF3=v3" );

    MATLAB Submit( "main_II" ); // execute the code contained in the matlab file 'main_II'

    MATLAB Submit( "xlswrite(filename, [t y],iii);" ); // write an excel file with all the simulation results; each sheet contains a simulation

    MATLAB Submit( "y1=y(:,1);" ); // create the vector y1 in Matlab
    MATLAB Submit( "y2=y(:,2);" ); // create the vector y2 in Matlab
    MATLAB Submit( "whos" );

    mat_y1 = MATLAB Get( y1 ); // JMP imports vectors y1, y2 and t as matrices
    mat_y2 = MATLAB Get( y2 );
    mat_t = MATLAB Get( t );

    n_timevector = Dim( mat_t ); // dimensions of matrix mat_t
    n = n_timevector[1]; // lenght of vector t

    //i=1;
    dt2 << addrows( n ); // for each simulation add n rows to the simulation table

    For( i = 1, i <= n, i += 1, // n is the vector length, write a row for each element of the time vector in table dt2

        row_n_dt2 = row_n_dt2 + 1;
        dt2:Pattern[row_n_dt2] = v0;
        dt2:x1[row_n_dt2] = mat_y1[i]; // different values for n rows
        dt2:M[row_n_dt2] = mat_y2[i];
        dt2:t[row_n_dt2] = mat_t[i];
        dt2:F1[row_n_dt2] = v1; // repeats same value for n rows
        dt2:F2[row_n_dt2] = v2;
        dt2:F3[row_n_dt2] = v3;

    );
);

 

View solution in original post

4 REPLIES 4
Craige_Hales
Super User

Re: Run Matlab simulations and create a JMP data table with simulations results

I usually create the output table's format in the GUI by making a new table with a single row that looks like what I want. Then use the red triangle to get the table script (no data). Paste that script into a editor, dt = paste;

Then remove the addrows from the script you just pasted, leaving just the column definitions. Remove the selected column bit too, if it shows up.

The loop you write to populate the table will use addrows(1) for each row and set each variable on that row. The default row will be the row just added, so

for( ... ,
    dt<<addrows(1);
    dt:par1 = ...;
    dt:par2 = ...;
    ...
    dt:y1 = ...;
    ...
)

Here's an example that added three rows in each loop Difference of lines.

Craige
MFVIT
Level IV

Re: Run Matlab simulations and create a JMP data table with simulations results

Hello,

thanks for you code, it was useful.

I still need some help. My problem is that time is not a factor of the original design. The original design has only par1, par2 and par3. For each combination of par1, par2 and par3 JMP runs Matlab and gets three vectors (t, y1 and y2). How can I ask JMP to add these three vectors to the result data table in such a way that I have the values for par1, par2 and par3 repeated n times, where n is the dimension of the t vector? 

Thanks.

Craige_Hales
Super User

Re: Run Matlab simulations and create a JMP data table with simulations results

here's some untested pseudo code that might fit what you are describing

for( par1 = 1, par1 <= 3, par1+=1, // 3...how ever many combinations there are
  for(par2 = 1, par2 <= 5, par2 +=1, // 5
    for(par3 = 1, par2 <= 2, par3+= 1, // 2
      /* get the vectors from matlab using par1,par2,par3 */
      /* somehow mat_t, mat_y1, and mat_y2 are now JSL matrices, n rows by 1 col */
      for( i = 1, i<= n, i+=1, // n is the vector length, write a row for each element
        dt<<addrows(1);
        dt:y1 = mat_y1[i];  // different values for n rows. also for y2
        dt:t = mat_t[i];
        dt:p1 = par1; // repeats same value for n rows. also for p2, p3
... close all the parens ...

I named the table variable p1 for par1 to simplify the scoping issues when column names are the same as variable names. I imagined you make separate calls to matlab for each combination of par1,2,3. I imagined those vectors show up as JSL matrices. Factors and Designs and matlab are not my strong area, I may be misunderstanding the issue.

Craige
MFVIT
Level IV

Re: Run Matlab simulations and create a JMP data table with simulations results

Thank you very much for your help. Based on your suggestions I was able to write a jsl code that solved my problem. Here is the code. 

 

 

MATLAB Submit( "iii=0;" ); // Initialize the counter in Matlab

For Each Row(
    dt1, 

    row_n_dt1 = row_n_dt1 + 1;

    v0 = :Pattern[row_n_dt1];
    v1 = :F1[row_n_dt1];
    v2 = :F2[row_n_dt1];
    v3 = :F3[row_n_dt1];
    MATLAB Submit( "iii=iii+1;" );

    MATLAB Send( v1 );
    MATLAB Send( v2 );
    MATLAB Send( v3 );

    MATLAB Submit( "FF1=v1" );
    MATLAB Submit( "FF2=v2" );
    MATLAB Submit( "FF3=v3" );

    MATLAB Submit( "main_II" ); // execute the code contained in the matlab file 'main_II'

    MATLAB Submit( "xlswrite(filename, [t y],iii);" ); // write an excel file with all the simulation results; each sheet contains a simulation

    MATLAB Submit( "y1=y(:,1);" ); // create the vector y1 in Matlab
    MATLAB Submit( "y2=y(:,2);" ); // create the vector y2 in Matlab
    MATLAB Submit( "whos" );

    mat_y1 = MATLAB Get( y1 ); // JMP imports vectors y1, y2 and t as matrices
    mat_y2 = MATLAB Get( y2 );
    mat_t = MATLAB Get( t );

    n_timevector = Dim( mat_t ); // dimensions of matrix mat_t
    n = n_timevector[1]; // lenght of vector t

    //i=1;
    dt2 << addrows( n ); // for each simulation add n rows to the simulation table

    For( i = 1, i <= n, i += 1, // n is the vector length, write a row for each element of the time vector in table dt2

        row_n_dt2 = row_n_dt2 + 1;
        dt2:Pattern[row_n_dt2] = v0;
        dt2:x1[row_n_dt2] = mat_y1[i]; // different values for n rows
        dt2:M[row_n_dt2] = mat_y2[i];
        dt2:t[row_n_dt2] = mat_t[i];
        dt2:F1[row_n_dt2] = v1; // repeats same value for n rows
        dt2:F2[row_n_dt2] = v2;
        dt2:F3[row_n_dt2] = v3;

    );
);