How do I load variable sized cell arryays into Simulink matlab function?
1 view (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!