pmatrix_pack function packs data to PSG PMatrix in MATLAB.
Syntax
[this_struct] = tbpsg_pmatrix_pack(name, data)
[this_struct] = tbpsg_pmatrix_pack(name, data, vars)
[this_struct] = tbpsg_pmatrix_pack(name, data, vars, options)
Description
[this_struct] = tbpsg_pmatrix_pack(name, data) returns (packs) structure this_struct with PSG PMatrix in Toolbox format (see PSG PMatrix in Toolbox). Names of variables (vars), by default are 'x1', …, 'x#n', where n is the number of columns in the sparse matrix data.
[this_struct] = tbpsg_pmatrix_pack(name, data, vars) packs sparse matrix with names of variables vars.
[this_struct] = tbpsg_pmatrix_pack(name, data, vars, options) packs sparse matrix with additional options.
Input Arguments
name |
name of sparse matrix; |
data |
pmatrix data; |
vars |
names of variables; |
options |
structure with field overwrite. If the input (data, or vars) of tbpsg_pmatrix_pack is MATLAB expression (not MATLAB variable), then the new variable with name pmatrix_name_keyword (name = input of tbpsg_pmatrix_pack, keyword = data, or vars) will be created. If variable pmatrix_name_keyword already exist and options.overwrite = 1 (default), then this variable will be overwritten. Otherwise the new variable with name pmatrix_name_keyword_i (i = 1,2,...) will be created. |
Remarks
• | name of pmatrix should not exceed 128 symbols, it is not case sensitive and includes only alphabetic characters, numbers, and underscore sign, “_”; |
• | data may be a sparse matrix or an ordinary matrix. In the later case data will be converted to a sparse matrix by default. |
Output Arguments
this_struct |
pointer to the PSG data structure. |
Example
Here is a PSG matrix in standard form:
x1 |
x2 |
x3 |
x4 |
11 |
22 |
0 |
0 |
0 |
33 |
44 |
0 |
0 |
0 |
0 |
55 |
66 |
0 |
77 |
0 |
0 |
88 |
0 |
99 |
In Sparse (Packed) Matrix format this matrix has the following structure:
x1 |
x2 |
x3 |
x4 |
1 |
1 |
11 |
|
1 |
2 |
22 |
|
2 |
2 |
33 |
|
2 |
3 |
44 |
|
3 |
4 |
55 |
|
4 |
1 |
66 |
|
4 |
3 |
77 |
|
5 |
2 |
88 |
|
5 |
4 |
99 |
|
To pack this pmatrix to the structure "toolboxstruc_arr" write:
vars = {'x1', 'x2', 'x3', 'x4'};
pmatrix=sparse([11 22 0 0; 0 33 44 0; 0 0 0 55; 66 0 77 0; 0 88 0 99]);
toolboxstruc_arr = tbpsg_pmatrix_pack('pmatrix_scenarios', pmatrix, vars);
Output:
>> toolboxstruc_arr
toolboxstruc_arr =
type: 'pmatrix'
data: [1x1 struct]
string: [1x1 struct]
>> toolboxstruc_arr.data
ans =
name: 'scenarios'
data: [5x4 double]
vars: 'x1 x2 x3 x4'
>> toolboxstruc_arr.data.data
ans =
(1,1) 11
(4,1) 66
(1,2) 22
(2,2) 33
(5,2) 88
(2,3) 44
(4,3) 77
(3,4) 55
(5,4) 99
>> toolboxstruc_arr.string
ans =
name: 'scenarios'
data: 'pmatrix'
vars: 'vars'
See also
PSG PMatrix in Toolbox, tbpsg_matrix_pack, tbpsg_vector_pack, tbpsg_point_pack, tbpsg_parameter_pack