Mahraz
Mahraz

Reputation: 103

set up data in MATLAB

I set up a problem in AMPL as follow :

Model

set A;
param B {A,A};

Data 

set A := 1 , 2  ;

I do not define my param B in my data section and now I want to define value of param B in MATLAB. I went through the examples that provided in the AMPL website but it does not work. I want B as follow :

B = rand(2,2)

can anyone tell me how I can do that in MATLAB please?

Upvotes: 1

Views: 64

Answers (1)

Mahraz
Mahraz

Reputation: 103

I found the answer fortunately

first the model part and the data part should be loaded in MATLAB. Then these commands can do the desired task :

B = ampl.getParameter('B');
B.setValues(rand(2,2));
ampl.display('B')
B :=
1 1   0.849129
1 2   0.678735
2 1   0.933993
2 2   0.75774

or

B.getValues

i1   i2   |  val                 
1.0  1.0  |  0.8491293058687771  
1.0  2.0  |  0.6787351548577735  
2.0  1.0  |  0.9339932477575505  
2.0  2.0  |  0.7577401305783334 

Upvotes: 0

Related Questions