Using 'char' within an embedded matlab function (simulink)

7 次查看(过去 30 天)
Hi Everyone,
When implementing the following code in a regular m file, I get no error:
data = zeros(16,1);
new_gens = char('Tegeta','Ngaka','Kiwira_1','Mchuchuma','Mufindi','Kinyerezi','Ubungo_Dar','Mwanza','Nyasa_Coal','Kihansi_2','Mpanga','Masigira','Ruhudji','Rumakali','Ikondo','Taveta');
filename2 = 'built_new.txt';
fid = fopen(filename2, 'w');
for i = 1:16
fprintf(fid,'pBuilt("%s") = %d;\r\n',new_gens(i,:),data(i));
end
fclose(fid);
However, when I use the same code within an embedded matlab function within simulink, I obtain the following error:
This call-site passes more inputs to this function than it can accept.
I checked that 'char' can be used within such simulink functions and it should work just fine. Do you know how to fix this?
I also tried making 'char' an extrinsic function and I received an error stating that the particular line was ignored since 'char' can be used within the simulink function. It then gave me an error stating:
subscripting into an mxArray is not supported
Again, I'm not sure what to do here so your help would be greatly appreciated!
Rhonda

回答(1 个)

Walter Roberson
Walter Roberson 2011-12-1
Simulink does not support signals of type char . You need to use a vector of the numeric values of the characters. For example,
0 + 'What''s up, Doc?'

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by