How do I load variable sized cell arryays into Simulink matlab function?

1 回表示 (過去 30 日間)
dvd7e
dvd7e 2018 年 5 月 24 日
コメント済み: dvd7e 2018 年 5 月 25 日
In a Simulink embedded matlab function, I would like to read in a text file of strings and store them as a variable sized cell array. For my application, the size is unknown beforehand and determined only from the input file, so it cannot be initialized/pre-allocated without reading the file.
Input file "input.txt" would look something like this:
string1
string2
string3
and then my embedded matlab like this:
function states = getStates()
coder.extrinsic('textscan')
fid = fopen('input.txt','r'); % Read only
temp = textscan(fid,'%s'); % Store results into a cell array of cells (?)
states = temp{1}'; % Extract to just a cell array (?)
fclose(fid); % close file handle
This code does work as a standalone function in Matlab (it returns a 1x3 cell array of strings), but does not in Simulink's embedded matlab. I get the following error:
Cell contents reference from a non-cell array object.
Function 'getStates.m' (#555.221.228), line 5, column 10:
"temp{1}"
Launch diagnostic report.
I've also tried coder.varsize(states) which doesn't work
Any idea how to read in a variable sized cell array in Simulink?
  2 件のコメント
TAB
TAB 2018 年 5 月 25 日
Are you using Matlab R2018a with string support in Simulink.
dvd7e
dvd7e 2018 年 5 月 25 日
No, I'm currently using 2017b. Is this pretty straight forward to do in Matlab 2018a?

サインインしてコメントする。

回答 (0 件)

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by