Filter löschen
Filter löschen

Please Tell me that how we can solve the error of "Number of Variables(NVARS) must be positive integer"?????

2 Ansichten (letzte 30 Tage)
% Load Solar Cell data
load elec_solar_iv_data.mat
% Display the Solar Cell model
Model = 'elec_solar';
open_system(Model)
close_system(Model, 0);
ParsListMain = {'Is', 'Iph', 'ec', 'Rs', 'Rp'};
InitGuessMain = [ 3e-7 3.8 1.5 .004 10 ];
ParsListTemp = {'TIPH1', 'EG', 'TXIS1'};
InitGuessTemp = [ .001 1.11 3 ];
load_system(Model);
set_param([Model '/Solar Cell'], 'prm', '3')
Pars = reshape([ParsListMain; cellstr(num2str(InitGuessMain'))'],1,[]);
set_param([Model '/Solar Cell'], Pars{:})
Pars = reshape([ParsListTemp; cellstr(num2str(InitGuessTemp'))'],1,[]);
set_param([Model '/Solar Cell'], Pars{:})
% Generate preliminary model curves and plot against data
num_lines = length(iv_data);
v_model = cell(1, num_lines);
i_model = cell(1, num_lines);
legend_info_data = cell(1, num_lines);
legend_info_model = cell(1, num_lines);
for idx_data = 1:num_lines
sim(Model);
v_model{idx_data} = Vo.signals.values;
i_model{idx_data} = Io.signals.values;
legend_info_data{idx_data} = [ 'Temp = ' ...
num2str(iv_data(idx_data).temperature) '\circC, Data'];
legend_info_model{idx_data} = [ 'Temp = ' ...
num2str(iv_data(idx_data).temperature) '\circC, Model'];
end
plot([iv_data.v], [iv_data.i], 'd', [v_model{:}], [i_model{:}])
xlabel('Solar cell output voltage (V)');
ylabel('Solar cell output current (A)');
legend([legend_info_data legend_info_model], 'Location', 'Best');
title('Model with Initial Parameter Values');
type elec_solar_lse.m
% Find room temperature data index
idx_data = find([iv_data.temperature]==25);
% Optimize parameters in main dialog tab of Solar Cell
ParsList = ParsListMain;
OptParsMain = ga(@elec_solar_lse, InitGuessMain, ...
optimset('TolX', 1e-3));
% Update Solar Cell block with optimized parameters
Pars = reshape([ParsList; cellstr(num2str(OptParsMain'))'],1,[]);
set_param([Model '/Solar Cell'], Pars{:});
% Display optimized parameters
display(sprintf(['Optimized parameters for the solar cell main ' ...
'dialog tab are:\n']));
display(sprintf('\t%5s = %s\n', Pars{:}));
% Find index into data for non-room temperatures
idx_data = find([iv_data.temperature]~=25);
% Optimize parameters in temperature dialog tab of Solar Cell
ParsList = ParsListTemp;
OptParsTemp = ga(@elec_solar_lse, InitGuessTemp, ...
optimset('TolX', 1e-3));
% Update Solar Cell block with optimized temperature parameters
Pars = reshape([ParsList; cellstr(num2str(OptParsTemp'))'],1,[]);
set_param([Model '/Solar Cell'], Pars{:});
% Display optimized parameters
display(sprintf(['Optimized parameters for the solar cell ' ...
'temperature dialog tab are:\n']));
display(sprintf('\t%5s = %s\n', Pars{:}));
for idx_data = 1:num_lines
sim(Model);
v_model{idx_data} = Vo.signals.values;
i_model{idx_data} = Io.signals.values;
end
plot([iv_data.v], [iv_data.i], 'd', [v_model{:}], [i_model{:}])
xlabel('Solar cell output voltage (V)');
ylabel('Solar cell output current (A)');
legend([legend_info_data legend_info_model], 'Location', 'Best');
title('Model with Optimized Parameter Values');
%%
bdclose(Model)

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by