from workspace to m.file

Hello. I want to take a variable from workspace to m-file. After I will process this variable and I will send to simulink. Could you help me please?

 Réponse acceptée

Paulo Silva
Paulo Silva le 31 Mar 2011

0 votes

if your m file is just code (not a function) the variables are in the same scope as the worspace, you just need to call them like you do in the workspace, if you are inside a function you should provide the variable as argument to the function or use fun=evalin('base','funname') inside your function code to get the variable value from the workspace.

7 commentaires

Recep
Recep le 31 Mar 2011
I take this error. I use parfor loop. cr is a variable from simulink to workspace via "To Workspace" block. What should I do?
"??? Error: MATLAB cannot determine whether "cr" refers to a function or variable.
See Parallel for Loops in MATLAB, "Unambiguous Variable Names".
Error in ==> parfor_deneme at 6
parfor idx=1:10"
Paulo Silva
Paulo Silva le 31 Mar 2011
perhaps you are trying to use a variable that's not created yet, To Workspace only creates the variable after the simulation is done.
Recep
Recep le 31 Mar 2011
I simulate my model via parfor loop. For this reason, now I do not know What should I do?
Paulo Silva
Paulo Silva le 31 Mar 2011
I never used parfor loops and have no clue what you are trying to do so unless you explain what you are trying to accomplish I can't help more.
Recep
Recep le 31 Mar 2011
I try optimization my model via parfor loop. I want to do Define the system I would like to optimize in Simulink and some measurement of quality of the solution based on the outputs of the simulation. I have to Use MATLAB workspace variables to define the parameters of the system that are changing, including initial conditions or input signals to the model. Could you help me please?
Paulo Silva
Paulo Silva le 31 Mar 2011
%initialize inputs
%loop x times or until some result if found
%start simulation and wait until it ends
%analyze simulation output and store info
%prepare inputs for another simulation
%return to start of the loop
Recep
Recep le 31 Mar 2011
Thank you, I hope I can solve problem and error. If you find more information, please let me know.

Connectez-vous pour commenter.

Plus de réponses (1)

Kaustubha Govind
Kaustubha Govind le 31 Mar 2011

0 votes

You might find it useful to read the documentation on Running Parallel Simulations. There is also Solution #1-6GRUQ3 that describes the broader usage of Parallel Computing Toolbox with Simulink.

1 commentaire

Recep
Recep le 31 Mar 2011
Thank you, I hope I can solve problem and error. If you find more information, please let me know.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Modeling dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by