Index in position 1 is invalid. Array indices must be positive integers or logical values.
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Anders Larsen
 el 9 de Nov. de 2021
  
    
    
    
    
    Comentada: Anders Larsen
 el 10 de Nov. de 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 comentarios
Respuesta aceptada
  David Hill
      
      
 el 9 de Nov. de 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)
Más respuestas (0)
Ver también
Categorías
				Más información sobre Matrix Indexing en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

