Index in position 1 is invalid. Array indices must be positive integers or logical values.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anders Larsen
am 9 Nov. 2021
Kommentiert: Anders Larsen
am 10 Nov. 2021
Hi,
I am trying to run a function inside a for loop with an index that should start at 1 however, MATLAB gives me an indexing error eventhough I have started the for loop from i = 1:c. I am running simulations in HYSYS through MATLAB.
global simname
simname = "C:\Users\Desktop\MEA1_25102021.tpl";
% Generating the design matrix with inputs
T = [45, 50]';
P = [1, 2]';
x = fullfact([2 2]);
x = [T(x(:, 1)), P(x(:,2))];
% Preallocating
c = length(x);
CO2removal = zeros(1, c);
reboil_duty = zeros(1, c);
% Calling the function
for i = 1:c
[CO2removal, reboil_duty]=simulation(x);
end
function [CO2removal, reboil_duty]=simulation(x)
hysys=actxserver('HYSYS.Application.V9.0');
hysys.ChangePreferencesToMinimizePopupWindows(1);
global simname
SimCase=hysys.SimulationCases.Open(simname);
SimCase.visible=true;
Solver=SimCase.solver;
Solver.Cansolve=false;
sprdsht=hysys.activeDocument.Flowsheet.Operations.Item('I/O');
%Setting input values (independent vars)
hyset(sprdsht.Cell('B10'),x(i, 1))
hyset(sprdsht.Cell('D10'),x(i, 2))
Solver.Cansolve=true;
while Solver.issolving
pause(on)
end
% Reading output/dependent/calculated values
sprdsht=hysys.activeDocument.Flowsheet.Operations.Item('I/O');
CO2removal(i) = sprdsht.Cell('D12').CellValue;
reboil_duty(i) = sprdsht.Cell('B12').CellValue;
end
Please let me know if you need more context.
Thanks.
0 Kommentare
Akzeptierte Antwort
David Hill
am 9 Nov. 2021
for i = 1:c
[CO2removal, reboil_duty]=simulation(x,i);%need to pass i to the function as well
end
function [CO2removal, reboil_duty]=simulation(x,i)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!