- Posts: 13
Editing MATLAB code
- Alfred
- Topic Author
Less
More
28 Jul 2020 12:25 #8490
by Alfred
Editing MATLAB code was created by Alfred
I am trying to edit the SAM generated MATLAB code. Such that I create script (SIF) of mine separately with inputs I want to change on the Sam MATLAB function file.
Aimed to enable making calculations for some properties outside SAM and return the values to the SAM code.
I have created a matfile.Obj which reads the .mat code generated from the script file (SIF).
However, when I make the necessary changes to the SAM code it doesn't seem to give the same results prior to the changes.
To clarify, examples of some changes:
In SIF.m file
sys_cap = % Nameplate capacity
RFA= 513.6 %Reflective aperture area m^2
Dvar = 7 %Design turbine gross output MW
DNI_des = 950 % Design point solar irradiation W/m^2
are all stored to a SIF.mat file and a matfileObj is created ==> matfileObj = matfile ('SIF.mat'); to read and obtain the variables as needed. using
b= matfileObj.sys_cap;
ssccall('data_set_ number', data, 'system_capacity', 'b');
j= matfileObj.I_bn_des;
ssccall('data_set_number', data, 'I_bn_des', 'j');
A_aperture =[ matfileObj.RFA ; matfileObj.RFA ];
ssccall( 'data_set_matrix', data, 'A_aperture', A_aperture );
etc
While the command for matfileObj seem to work correctly. The SAM function code appears to give wrong results.
N.B: Changing the number directly in the SAM code appears to work fine. Also I tried changing the ssccall command for number to array (i.e. 'data_set_number' to either 'data_set_array' or 'data_set_matrix') but as expected it did not work due to the code constraints
tcslinear_fresnel errors:
precheck input: variable 'demand_var' (<array>) of wrong type, <number> required.
tcslinear_fresnel errors:
precheck input: variable 'demand_var' (<matrix>) of wrong type, <number> required.
I have also added the edited code.
Aimed to enable making calculations for some properties outside SAM and return the values to the SAM code.
I have created a matfile.Obj which reads the .mat code generated from the script file (SIF).
However, when I make the necessary changes to the SAM code it doesn't seem to give the same results prior to the changes.
To clarify, examples of some changes:
In SIF.m file
sys_cap = % Nameplate capacity
RFA= 513.6 %Reflective aperture area m^2
Dvar = 7 %Design turbine gross output MW
DNI_des = 950 % Design point solar irradiation W/m^2
are all stored to a SIF.mat file and a matfileObj is created ==> matfileObj = matfile ('SIF.mat'); to read and obtain the variables as needed. using
b= matfileObj.sys_cap;
ssccall('data_set_ number', data, 'system_capacity', 'b');
j= matfileObj.I_bn_des;
ssccall('data_set_number', data, 'I_bn_des', 'j');
A_aperture =[ matfileObj.RFA ; matfileObj.RFA ];
ssccall( 'data_set_matrix', data, 'A_aperture', A_aperture );
etc
While the command for matfileObj seem to work correctly. The SAM function code appears to give wrong results.
N.B: Changing the number directly in the SAM code appears to work fine. Also I tried changing the ssccall command for number to array (i.e. 'data_set_number' to either 'data_set_array' or 'data_set_matrix') but as expected it did not work due to the code constraints
tcslinear_fresnel errors:
precheck input: variable 'demand_var' (<array>) of wrong type, <number> required.
tcslinear_fresnel errors:
precheck input: variable 'demand_var' (<matrix>) of wrong type, <number> required.
I have also added the edited code.
Attachments:
Please Log in or Create an account to join the conversation.
- Alfred
- Topic Author
Less
More
- Posts: 13
30 Jul 2020 04:29 #8501
by Alfred
Replied by Alfred on topic Editing MATLAB code
I found a mistake on my method of calling the needed vairables.
What I did was run the a MATLAB script file in the SAM function code as follow
function noerror
run SIF.m;
end
load ('SIF.mat','sys_cap','q_max_out','x_des','q_des','sm','DNI_des','nModBl','lat','m_dot','Tsf_amb','RFA','LCM','T_cold','T_out','Tamb_des', 'dvar', 'w_per_wash');
SIF = load ('SIF.mat');
Then call the varaible as need needed using
SIF.variablename()
ssccall('data_set_number', data, 'q_max_aux',q_max_out)
What I did was run the a MATLAB script file in the SAM function code as follow
function noerror
run SIF.m;
end
load ('SIF.mat','sys_cap','q_max_out','x_des','q_des','sm','DNI_des','nModBl','lat','m_dot','Tsf_amb','RFA','LCM','T_cold','T_out','Tamb_des', 'dvar', 'w_per_wash');
SIF = load ('SIF.mat');
Then call the varaible as need needed using
SIF.variablename()
ssccall('data_set_number', data, 'q_max_aux',q_max_out)
Please Log in or Create an account to join the conversation.
Moderators: pgilman