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