Is it possible to write to a MATLAB workspace parameter from within a TLC file?

조회 수: 2 (최근 30일)
David
David 2012년 10월 1일
답변: Juan Reyes 2016년 7월 15일
I'm generating a level-2 matlab s-function based on a m file and it is working perfectly since I'm able to modify workspace variable from m file.
However, when I generate code or simulate in accelerator mode, I need to provide a tlc file that does the same thing than the m file and I have hard time to do so. I'm not able to modify a workspace variable from the tlc.
I tried the following :
%assign b = FEVAL("evalin","base","var1 = 10")
Thanks for your help.
David.

답변 (2개)

Kaustubha Govind
Kaustubha Govind 2012년 10월 1일
편집: Kaustubha Govind 2012년 10월 1일
I'm guessing this is not working, because you are doing the equivalent of:
>> b = evalin('base','var1 = 10')
When executed in the MATLAB command window, I see this error:
>> b = evalin('base','var1 = 10')
Error: The expression to the left of the equals sign is not a valid target for an assignment.
Try just:
%<FEVAL("evalin","base","var1 = 10;")>
  댓글 수: 2
David
David 2012년 10월 2일
Hi Kaustubha,
You are right about the "b = evalin('base','var1 = 10')" not working. In fact I tried the following "b = feval('evalin','base','var1', '10')"which wasn't working either but no error.
Your suggestion seems to cause an error when generating code from tlc. Here's what I got with only your line in the output function of the tlc:
### Building the Accelerator target for model: two Setting environment for using Microsoft Visual Studio 2008 Beta2 x64 tools.
Microsoft (R) Program Maintenance Utility Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved.
### Compiling two_acc.c C:\PROGRA~1\MATLAB\R2012b\bin\mex -c -win64 OPTIMFLAGS="/Od /Oy- /DNDEBUG" -f C:\Users\mslog01\AppData\Roaming\MATHWO~1\MATLAB\R2012b\mexopts.bat two_acc.c two_acc.c two_acc.c(33) : error C2143: syntax error : missing ';' before '{'
C:\PROGRA~1\MATLAB\R2012B\BIN\MEX.PL: Error: Compile of 'two_acc.c' failed.
NMAKE : fatal error U1077: 'C:\PROGRA~1\MATLAB\R2012b\bin\mex.BAT' : return code '0x9' Stop. The make command returned an error of 2 'An_error_occurred_during_the_call_to_make' n'est pas reconnu en tant que commande interne ou externe, un programme ex‚cutable ou un fichier de commandes.
### Build procedure for model: 'two' aborted due to an error.
If I comment the new suggested line it compiles.
Thanks.
Kaustubha Govind
Kaustubha Govind 2012년 10월 2일
David: What exactly is the code generating around line#33 of two_acc.c? This file may be hard to read, so I would recommend performing a regular code-generation (Ctrl+B) and see if you can reproduce the same error?

댓글을 달려면 로그인하십시오.


Juan Reyes
Juan Reyes 2016년 7월 15일
I had the same problem. Try this inside your TLC code:
%matlab assignin("base", "YourWorkspaceVar", %<foo> )
base: Matlab's base workspace; YourWorkspaceVar: Workspace new variable; foo: a variable inside the TLC workspace to be exported to base workspace;

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by