Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
dvd7e
dvd7e le 24 Mai 2018
Commenté : dvd7e le 25 Mai 2018
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 commentaires
TAB
TAB le 25 Mai 2018
Are you using Matlab R2018a with string support in Simulink.
dvd7e
dvd7e le 25 Mai 2018
No, I'm currently using 2017b. Is this pretty straight forward to do in Matlab 2018a?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by