Send variable from c to matlab

Hi all,
I have a c program that set variable into matlab, using matlab Engine.
ep = engOpen(NULL);
...
engPutVariable(ep, "var", var);
Everything is OK except that I want to send the variable,
to regular matlab workspace
and not to matlab Engine.
Any help ???
thx

 Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Oct. de 2011

1 voto

Your C program is the "MATLAB engine" in MATLAB terminology.
I have not been able to establish this as a fact so far, but as best I can tell reading between the lines, engPutVariable() writes the variable into the "base workspace" of the MATLAB process associated with the engine.
There is no mechanism provided to write a variable in to the workspace of a particular function because no functions can be running in the MATLAB process at the time engPutVariable() is executed (or so my reading suggests.)

6 comentarios

zohar
zohar el 31 de Oct. de 2011
Hi Walter,
What do you mean " There is no mechanism provided to write a variable in to the workspace of a particular function " ?
When I execute the command engOpen(NULL) it's open a weird matlab workspace , who looks like an old version of matlab and not the regular matlab workspace.
Any suggestion ?
Walter Roberson
Walter Roberson el 31 de Oct. de 2011
What does a "regular matlab workspace" look like to you?
Regular MATLAB offers:
- A "base" workspace. This is the same workspace that you get if you work entirely at the command line. The variables that exist by default in the "base" workspace are only "i" and "j", both with the value sqrt(-1) . Everything else, including "ans", is only created at need.
- A "global" workspace. This workspace is accessible on a variable-by-variable basis, by using the "global" command followed by a variable name to indicate that the global instance should be accessed. There are no variables in the global workspace by default.
- one workspace per function which is currently in the call chain (either actively running, or called another function and so was suspended itself, or was interrupted by a timer or a callback). This workspace contains all of the variables used by the function, and other than in special circumstances, the workspace will have all those variables cleared out when the workspace goes out of scope. By default, each function executing or in temporary suspension has a separate workspace.
- one workspace per function that is not currently in the execution stack, if the function is the owner of a variable that is being used as part of an active closure. This one is a bit difficult to explain. By default, closures do not exist.
None of these different types of workspaces has any obviously different appearance than any other. You would probably have to go back to MATLAB version 4 for obvious differences in the look of a workspace.
Are you perhaps talking about a desktop or inspector tool of some kind? Or are you perhaps referring to the appearance of the command prompt or command line??
Perhaps posting a screen short might help.
zohar
zohar el 3 de Nov. de 2011
Hi Walter and many thanks
OK, I understand what you are saying.
The solution :
There is workspace("weird matlab workspace") and desktop environment ("regular matlab workspace"),the desktop environment is just a fancy interface to make the underlying command-line MATLAB easier to use.
I wanted to set variables into matlab and to see them using desktop environment. In order to do it, in the workspace command-line type
desktop.
Walter +1
Thanks
Walter Roberson
Walter Roberson el 3 de Nov. de 2011
The MATLAB Engine interface is the wrong interface for such things. The Engine interface is primarily for doing computations.
The MATLAB Automation Server might be more appropriate. See
http://www.mathworks.com/help/techdoc/matlab_external/f135590.html
Marisol Sierra
Marisol Sierra el 13 de Jun. de 2018
Hey... did you solve the problem?
Walter Roberson
Walter Roberson el 13 de Jun. de 2018
Correction to a minor point from my 2011 posting:
i and j are not variables that exist by default. Instead, i and j are functions, just like pi and inf and nan

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 30 de Oct. de 2011

Comentada:

el 13 de Jun. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by