Run a simulink/script from a pushbutton

조회 수: 1 (최근 30일)
Nu9
Nu9 2011년 9월 28일
편집: TABOUNI Khadidja 2017년 5월 22일
hi
i've a script in a PB_function and when i push the button it shows me a lot off errors.Running the originar script without the PB it works but when i use in PB_function doesn't work:
??? Error using ==> gui_passdata>pb2_call at 438
Error due to multiple causes.
Caused by:
Error using ==> gui_passdata>pb2_call at 438
Error evaluating parameter 'VariableName' in
'modelo_pilha1/B': Undefined function or variable 'P1'.
in the scrip i've a simulink model that uses the variable P1 but i don't change anything and it doesn't work.
a(1)=5*10^(-3);
b(1)=5*10^(-2);
PP1=a(1)+(b(1)-a(1))*rand;
P1=[t PP1];
to run the simulink model
load_system('modelo_pilha1'); % correr simulink e obter Vsimulado
sim('modelo_pilha1');
  댓글 수: 2
TAB
TAB 2011년 9월 28일
Which block is using 'P1' in your model ?
Where the value of 'P1' is defined?
Is it defined in base workspace?
Nu9
Nu9 2011년 9월 28일
when i run the original script it saves in workspace all the variables. The value P1 isn't defined in the script.
The block tiype is-from workspace

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

채택된 답변

TAB
TAB 2011년 9월 28일
From workspace block reads wariable from base workapace.
If you are defining and writing P1 variable from pushbutton callback function, then it will not saved in base workspace. Every function have its own workspace and they not shares variables.
Try saving P1 in .mat file and load this .mat in base wokspace before starting the simulation.
P1=[t PP1];
save('Myfile.mat','P1');
evalin('base','load(''Myfile.mat'')');
%load model & Simulate
load_system('modelo_pilha1'); % correr simulink e obter Vsimulado sim('modelo_pilha1');
  댓글 수: 4
Nu9
Nu9 2011년 9월 29일
thanks for thr tip, now i need to solve just a problem about some variables, some are vector or matrices.I don't find th way to save that type off data in save doc and other doc's, only shows struct.
one of the variables- V value in workspace - <10x8x51 double>
TAB
TAB 2011년 9월 29일
'save' funcn saves all type of data into .mat file whatever its type. You just define your data and run 'save' function.
You can check yourself on base workspace.
Define Arruays, Matrices, Structures.... or any kind of data in Command window. These variables will be placed in base workspace.
Now run 'save' function in command window to save base workspace in a .mat file. Clear all the data from base workspace by hitting 'clear all' command.
Now load your .mat using 'load'. You can see all the defined data in workspace.
Same concept applies to function workspace.

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

추가 답변 (1개)

Kaustubha Govind
Kaustubha Govind 2011년 9월 28일
By default, Simulink looks for parameter variables in the base workspace. You variable P1 is created in the function workspace, where Simulink isn't looking. To have it looks for P1 in the current/function workspace, use:
load_system('modelo_pilha1');
opt=simset('SrcWorkspace','current');
sim('modelo_pilha1',opt);
Alternatively, you can follow Tabrez's suggestion of loading the variables into the base workspace.
  댓글 수: 3
TABOUNI Khadidja
TABOUNI Khadidja 2017년 5월 22일
did this answer hel you?
TABOUNI Khadidja
TABOUNI Khadidja 2017년 5월 22일
편집: TABOUNI Khadidja 2017년 5월 22일
i need to do the same thing but save whatever the sim func gives me

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by