Store variable to file in Simulink

Dear MATLAB community,
I am trying to store an array of vector variable to a file in Simulink from a MATLAB function block.
I have tried
(1)'save('savevec.dat', 'vec');'
but function 'save' is not suppoorted as coder.extrinsic.
I have also tried
(2)'matlab.io.saveVariablesToScript('savevec.m', 'vec')'
but Simulink does not seem to be able to detect variable 'vec' in case (2).
I am reluctant to use Simulink's sink 'to file' block, as vec suppose to be internal calculations.
Thanks in advance for your help.
Regards.

 Respuesta aceptada

Loong
Loong el 15 de Sept. de 2014

0 votos

It turns out that what I needed are dlmwrite, dlmread..

Más respuestas (1)

Sean de Wolski
Sean de Wolski el 15 de Sept. de 2014

0 votos

Why not make vec a second output of the function&block and then use the "To File" block?

1 comentario

Loong
Loong el 15 de Sept. de 2014
Editada: Loong el 15 de Sept. de 2014
Hi, Thanks for the reply. My vec is approximately 100k array in size. I made 'vec' persistent for each Simulink cycle. When I try to make 'vec' as additional output, I can no longer make 'vec' persistent and I will get errors like "Undefined function or variable 'vec'. The first assignment to a local variable determines its class." My objective is to store 'vec' either to a file or to a workspace, preferably called within the MATLAB function block run by Simulink. Any idea? Thanks.

Iniciar sesión para comentar.

Categorías

Productos

Preguntada:

el 15 de Sept. de 2014

Respondida:

el 15 de Sept. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by