# Error in running 22mw with S-Fuction for OpenFAST in Matlab

**URL:** <https://forums.nlr.gov/t/error-in-running-22mw-with-s-fuction-for-openfast-in-matlab/9064>\
**Category:** Controls\
**Created:** [July 9, 2025, 3:44pm UTC](https://forums.nlr.gov/t/error-in-running-22mw-with-s-fuction-for-openfast-in-matlab/9064 "2025-07-09T15:44:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yongxiang.Lei](https://avatars.discourse-cdn.com/v4/letter/y/3ec8ea/32.png) [@Yongxiang.Lei](https://forums.nlr.gov/u/Yongxiang.Lei)\
**Post date:** [July 9, 2025, 3:44pm UTC](https://forums.nlr.gov/t/error-in-running-22mw-with-s-fuction-for-openfast-in-matlab/9064/1 "2025-07-09T15:44:53Z")

</div>

Hello,

I am encounting an issue when I was using S-function to OpenFAST, the following error shows for the reading process.

Did anyone meet this before.

I would be so grateful if any suggestions are given.

# Best regards, Yong

Unable to perform assignment because the size of the left side is 1-by-7 and the size of the right side is 6-by-1.

# Error in HD2Matlab\>ParseFASTTable (line 274) [Table(i,:),~,~,nextIndex] = sscanf(line,‘%f’,nc); ^^^^^^^^^^ Error in HD2Matlab (line 122) [DataOut.Joints] = ParseFASTTable(line, fid, NJoints); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Error in GetFASTPar\_Subfile (line 31) p = HD2Matlab(SubfileName,2); % get parameter data (2 header lines) ^^^^^^^^^^^^^^^^^^^^^^^^ Error in ReadWrite\_FAST (line 29) [HDP, HDFile] = GetFASTPar\_Subfile(FP, ‘HydroFile’, fast.FAST\_directory, fast.FAST\_directory,true); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Error in runFAST2 (line 42) [Param,Cx] = ReadWrite\_FAST(fast); ^^^^^^^^^^^^^^^^^^^^

[this\_dir,~,~] = fileparts(mfilename(‘fullpath’));

% Compile FAST for use with simulink & mex using openfast docs  
fast.FAST\_SFuncDir = ‘C:\yongxiang\Code\windctrolcode22mw\IEA-22-280-RWT-main\OpenFAST\IEA-22-280-RWT-Monopile’; %%%% NEED FOR SIMULINK  
fast.FAST\_InputFile = ‘IEA-22-280-RWT-Monopile.fst’; % FAST input file (ext=.fst)  
fast.FAST\_directory = ‘C:\yongxiang\Code\windctrolcode22mw\IEA-22-280-RWT-main\OpenFAST\IEA-22-280-RWT-Monopile’; % Path to fst directory files

% Simulink Parameters  
% Model  
%simu.SimModel = fullfile(this\_dir,‘Simulink’,‘ROSCO’);  
simu.SimModel = ‘WT’;

% Script for loading parameters  
simu.ParamScript = fullfile(this\_dir,‘Utilities’,‘load\_ROSCO\_params’);

%% Simulink Setup

[ControlScriptPath,ControScript] = fileparts(simu.ParamScript);  
addpath(ControlScriptPath);  
addpath(fast.FAST\_SFuncDir);  
addpath(‘Utilities’)  
%% Read FAST Files & Load ROSCO Params from DISCON.IN

[Param,Cx] = ReadWrite\_FAST(fast);

% Simulation Parameters  
simu.TMax = Param.FP.Val{contains(Param.FP.Label,‘TMax’)};  
simu.dt = Param.FP.Val{contains(Param.FP.Label,‘DT’)};  
simu.wPA = 8.6; % Pitch actuator natural frequency, rad/sec  
simu.zetaPA = 0.707; % Pitch actuator damping ratio, unitless  
simu.PC\_MaxRat = 0.3;  
[R,F] = feval(ControScript,Param,simu);

%% Premake OutList for Simulink

OutList = {‘Time’};  
OutList = [OutList;  
Param.IWP.OutList{1,1};  
Param.EDP.OutList{1,1};  
Param.ADP.OutList{1,1};  
Param.SvDP.OutList{1,1};  
];

for iOut = 2:length(OutList)  
OutList{iOut} = OutList{iOut}(2:end-1); %strip "s  
end

%% Exectute FAST

% Using Simulink/S\_Func  
FAST\_InputFileName = [fast.FAST\_directory,filesep,fast.FAST\_InputFile];  
TMax = simu.TMax;

SimulinkModel = simu.SimModel;

%%%Load the NN parameters  
warning off  
s\_dim = 3; % state dimension  
a\_dim = 3; % action dimension  
par\_memory\_all = ;  
controller\_update\_num = 200;  
% disp(update\_num);  
%controller\_update\_num = update\_num;  
init\_idx = 1;  
model = ‘WT’;  
load\_system(model);  
actor\_net\_path = [pwd, ‘\Networks\Actor\Actornet.mat’];  
critic\_net\_path = [pwd, ‘\Networks\Critic\Criticnet.mat’];  
%  
Actor\_net = importONNXNetwork([‘Networks\Actor\actor\_’,num2str(controller\_update\_num),‘.onnx’], ‘InputDataFormats’, ‘BC’, ‘OutputLayerType’, ‘regression’, ‘TargetNetwork’, ‘dlnetwork’);  
save(actor\_net\_path,‘Actor\_net’)  
set\_param([model,‘/PPO Controller/Actor’],‘NetworkFilePath’, actor\_net\_path)  
%  
Critic\_net = importONNXNetwork([‘Networks\Critic\critic\_’,num2str(controller\_update\_num),‘.onnx’], ‘InputDataFormats’, ‘BC’, ‘OutputLayerType’, ‘regression’, ‘TargetNetwork’, ‘dlnetwork’);  
save(critic\_net\_path,‘Critic\_net’)  
set\_param([model,‘/PPO Controller/Critic’],‘NetworkFilePath’, critic\_net\_path)

Out = sim(SimulinkModel, ‘StopTime’, num2str(simu.TMax));  
sigsOut = get(Out,‘sigsOut’); %internal control signals

%% Get OutData

SFuncOutStr = ‘.SFunc’;

% Try text first, then binary  
[OutData,OutList] = ReadFASTtext([fast.FAST\_directory,filesep,fast.FAST\_InputFile(1:end-4),SFuncOutStr,‘.out’]);  
if isempty(OutData)  
[OutData,OutList] = ReadFASTbinary([fast.FAST\_directory,filesep,fast.FAST\_InputFile(1:end-4),SFuncOutStr,‘.outb’]);  
end

% Dump data to structure  
for i = 1:length(OutList)-6  
simout.(OutList{i}) = OutData(:,i);  
end

observation = squeeze(Out.observation)‘; % dim 6  
action\_std = squeeze(Out.action\_std)’; % action 3 + logprob dim 4  
epi\_memory = [observation, action\_std]; % dim 10  
reward = Out.reward.Data;  
value = Out.value;  
epi\_rewards = [reward, value]; % dim 2  
mu = squeeze(Out.mu)‘;  
sigma = squeeze(Out.sigma)’;  
epi\_act\_output = [mu, sigma]; % dim 6  
reshape\_epi\_memory = epi\_memory(init\_idx:end, 1: s\_dim+a\_dim+1); % state & action\_sampled & logprob dim=7  
reshape\_epi\_reward = epi\_rewards(init\_idx:end, :); % dim=2  
reshape\_epi\_act\_output = epi\_act\_output(init\_idx:end, :); % dim=6  
par\_memory = [reshape\_epi\_memory, reshape\_epi\_reward, reshape\_epi\_act\_output];  
par\_memory\_all = [par\_memory\_all; par\_memory];  
%  
disp(‘Simulation is over.’);  
save([‘Memories/par\_memory\_’,num2str(controller\_update\_num),‘.mat’], ‘par\_memory\_all’)

---

<div class="post-metadata">

**Author:** ![Daniel.Zalkind](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Daniel.Zalkind](https://forums.nlr.gov/u/Daniel.Zalkind)\
**Post date:** [July 10, 2025, 3:10pm UTC](https://forums.nlr.gov/t/error-in-running-22mw-with-s-fuction-for-openfast-in-matlab/9064/2 "2025-07-10T15:10:31Z")

</div>

Hi,

This appears to be an error in the matlab helper functions, rather than the S-function. These helper functions are no longer maintained in favor of openfast-io ([openfast/openfast\_io at main · OpenFAST/openfast · GitHub](https://github.com/OpenFAST/openfast/tree/main/openfast_io)).

I think the error may become clear if you set a break point at 274 in `ParseFASTTable` and observe the line being read.

If the OpenFAST model works from the command line, I would presume it works using the S-interface. I usually suggest starting with [the simple Simulink examples here](https://github.com/OpenFAST/openfast/tree/main/glue-codes/simulink/examples) and building the complexity. You may need to adapt the matlab tools so they work with the latest input structure of OpenFAST.

I hope this helps.

Best, Dan

---

<div class="post-metadata">

**Author:** ![Yongxiang.Lei](https://avatars.discourse-cdn.com/v4/letter/y/3ec8ea/32.png) [@Yongxiang.Lei](https://forums.nlr.gov/u/Yongxiang.Lei)\
**Post date:** [July 17, 2025, 2:44pm UTC](https://forums.nlr.gov/t/error-in-running-22mw-with-s-fuction-for-openfast-in-matlab/9064/3 "2025-07-17T14:44:23Z")

</div>

Hi Daniel,

Many thanks for your guidance. I would like to use **matlab S-Function to call the 22MW wind turbine** for testing control target.

As you mentioned eariler, I use the simple Simulink examples to try, it runs completely. Then yet, when I changed the path to a 22mw .fst path, its gives me the error of invalid numerical input.

 ![image](https://europe1.discourse-cdn.com/nrel/original/2X/0/0982271257185d09718c7adb051a6d256433cada.png)

Could you please help to look at?

Best regards,  
Yong

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [July 17, 2025, 5:10pm UTC](https://forums.nlr.gov/t/error-in-running-22mw-with-s-fuction-for-openfast-in-matlab/9064/4 "2025-07-17T17:10:43Z")

</div>

Dear @Yongxiang.Lei,

My guess is that your OpenFAST input file(s) for the IEA Wind 22-MW RWT are not compatible with the version of OpenFAST within Simulink (i.e., the OpenFAST S-Function) you are running. Input file changes with each release of OpenFAST are documented here: [4.1.2. API changes between versions — OpenFAST v4.1.1 documentation](https://openfast.readthedocs.io/en/main/source/user/api_change.html). And you can always enable the `Echo` option in OpenFAST input files to debug issues associated with input file processing.

Best regards,
