and if i run with ("sim"command)simulink blocks values are saving to worksapce,,and if i run with ("start ,simulation command"),,my simulink variables are not saving to workspace
Vous suivez désormais cette question
- Les mises à jour seront visibles dans votre flux de contenu suivi.
- Selon vos préférences en matière de communication il est possible que vous receviez des e-mails.
how to pass variables from simulink to workspace,when simulink has been paused from MATLAB Script
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Arun Badigannavar
le 14 Déc 2012
I am running two simulink model from matlab script(with "sim" command),,now i want to pause the running simulink model in the middle and send the data from "to workspace block" to my matlab workspace at the time wen i paused it,,,,,actually my requirmnet is meeting if i directly run my simulink model from simulnk start pause button,,,but its not working through script
4 commentaires
Arun Badigannavar
le 14 Déc 2012
Arun Badigannavar
le 14 Déc 2012
help me out,,if anyone know abt this
tulika Roy
le 31 Déc 2012
I am running the simulink model with a script file I am taking a for loop, after 1 cycle value model runs but in next cycle value it deleted the old value. figure I can use using 'hold on' but how to store and retain old array?
Arun Badigannavar
le 3 Jan 2013
Start a new question thread Tulika Roy
Réponses (2)
Azzi Abdelmalek
le 14 Déc 2012
Use
set_param('Yourmodel','Simulationcommand','start')
and your data will be saved to workspace
5 commentaires
Azzi Abdelmalek
le 14 Déc 2012
Maybe you should close a loop then start another loop, I did'nt try it (I have'nt Matlab where I am).
Arun Badigannavar
le 17 Déc 2012
ya i do feel the same but it will lenthier
Azzi Abdelmalek
le 17 Déc 2012
What is 'lenthier' ?
Arun Badigannavar
le 17 Déc 2012
I mean to say i have to write for loop again
Azzi Abdelmalek
le 17 Déc 2012
Arun, I tested your problem in a loop, and it worked, the initial value of the unit delay don't change when you pause simulation. I don't know why it don't work for you.
TAB
le 14 Déc 2012
@Arun, I hope that you don't have any strange varsion of matlab (like Matlab R. Strange).
sim() command will not return till simulation is completed, so off-course your script will never go ahead to execute other commands like pause.
And, see below snap. When I run and pause the model from script using SimulationCommand, then To Workspace block output is saved in workspace. It should work for you also.

18 commentaires
Arun Badigannavar
le 14 Déc 2012
these commands i have inside a for loop,,,
Azzi Abdelmalek
le 14 Déc 2012
Modifié(e) : Azzi Abdelmalek
le 14 Déc 2012
Arun, can you post your code
Arun Badigannavar
le 14 Déc 2012
for i=1:1:25
set_param('course_speed_position', 'Simulationcommand', 'start')
set_param('course_speed_position1', 'Simulationcommand', 'start')
set_param('course_speed_position','StopTime', sprintf('%d',i));
set_param('course_speed_position1','StopTime',sprintf('%d',i));
pause(0.5)
set_param('course_speed_position', 'Simulationcommand', 'pause')
set_param('course_speed_position1', 'Simulationcommand', 'pause')
pause(0.5)
set_param('course_speed_position', 'Simulationcommand', 'continue')
set_param('course_speed_position1', 'Simulationcommand', 'continue')
assignin('base', 'x_F', x_F);
assignin('base', 'y_F', y_F);
assignin('base', 'x_T', x_T);
assignin('base', 'y_T', y_T);
assignin('base', 'course_F', course_F);
assignin('base', 'speed_F', speed_F);
assignin('base', 'course_T', course_T);
assignin('base', 'speed_T', speed_T);
figure(5)
plot(x_F,y_F,'r*',x_T,y_T,'r*')
[columns,rows] = size(x_F)
assignin('base', 'columns', columns);
assignin('base', 'rows',rows);
Arun Badigannavar
le 14 Déc 2012
this is wat am doing,,but its not saving to workspace,,
Arun Badigannavar
le 14 Déc 2012
for i=1:1:25
set_param('course_speed_position','StopTime', sprintf('%d',i));
set_param('course_speed_position1','StopTime',sprintf('%d',i));
% pause(0.5)
% Execute the model which we have opened in the above command
options = simset('SrcWorkspace','current');
simOut = sim('C:\Documents and Settings\admin\Desktop\New Folder (5)\02_12_2012(Simulink blocks)\Resolved Models\Speed+Position+Course\course_speed_position.mdl');
simOut1 = sim('C:\Documents and Settings\admin\Desktop\Trial Testing\course_speed_position1.mdl');
%plotting of Firing and Target platform in a single plot
%asssign these values on workspace to see the data
assignin('base', 'x_F', x_F);
assignin('base', 'y_F', y_F);
assignin('base', 'x_T', x_T);
assignin('base', 'y_T', y_T);
assignin('base', 'course_F', course_F);
assignin('base', 'speed_F', speed_F);
assignin('base', 'course_T', course_T);
assignin('base', 'speed_T', speed_T);
figure(5)
plot(x_F,y_F,'r*',x_T,y_T,'r*')
[columns,rows] = size(x_F)
assignin('base', 'columns', columns);
assignin('base', 'rows',rows);
end
end
Arun Badigannavar
le 14 Déc 2012
this is the secod way am trying out
TAB
le 14 Déc 2012
In your code, you are starting the simulation and then setting the stop time. I don't think this is proper way of simulating model.
Ok...One more try....
Can you explain what you are trying to do i simple words, so anyone here can suggest something.
Arun Badigannavar
le 14 Déc 2012
but it simulates nicely,without error
Arun Badigannavar
le 14 Déc 2012
Mr TAB My Strange MATLAB works propely ,,and it will not send values back to workspace until for loop will finish
Azzi Abdelmalek
le 17 Déc 2012
If you want to set stop time, do it before start sim or after pause sim. It does'nt make sens to do it after start sim. Other thing, are you sur you are runing your model from m file, if yes, why are you then, using assignin command?
Arun Badigannavar
le 18 Déc 2012
Modifié(e) : Walter Roberson
le 18 Déc 2012
for i=1:1:500
set_param('course_speed_position','StopTime', sprintf('%d',i));
set_param('course_speed_position1','StopTime',sprintf('%d',i));
% pause(0.5)
% Execute the model which we have opened in the above command
simOut = sim('C:\Documents and Settings\admin\Desktop\New Folder (5)\02_12_2012(Simulink blocks)\Resolved Models\Speed+Position+Course\course_speed_position.mdl');
simOut1 = sim('C:\Documents and Settings\admin\Desktop\Trial Testing\course_speed_position1.mdl');
options = simset('SrcWorkspace','current');
%plotting of Firing and Target platform in a single plot
%asssign these values on workspace to see the data
assignin('base', 'x_F', x_F);
assignin('base', 'y_F', y_F);
assignin('base', 'x_T', x_T);
assignin('base', 'y_T', y_T);
assignin('base', 'course_F', course_F);
assignin('base', 'speed_F', speed_F);
assignin('base', 'course_T', course_T);
assignin('base', 'speed_T', speed_T);
figure(5)
plot(x_F,y_F,'r*',x_T,y_T,'r*')
[columns,rows] = size(x_F)
assignin('base', 'columns', columns);
assignin('base', 'rows',rows);
rto = get_param(gcb,'RuntimeObject')
% RTOO= rto.OutputPort.Data
end
Arun Badigannavar
le 18 Déc 2012
assignin am using to plot it and to put in to base workspace,,so that my other simulink model can access the data which are available from these models output
Walter Roberson
le 18 Déc 2012
Wouldn't you want to stop at time i+1 rather than i ?
Azzi Abdelmalek
le 18 Déc 2012
Modifié(e) : Azzi Abdelmalek
le 18 Déc 2012
Arun, If speed_F is the output of another simulink model, that means that this variable is already in workspace, if not, then just use to workspace block
Arun Badigannavar
le 18 Déc 2012
no actually these value in workspace i get wen i stop the model,,rather i want to get the data of workspace,when i pause the simulation
Azzi Abdelmalek
le 18 Déc 2012
I do'nt understand. Even you pause your simulation, your data will be in workspace.
Arun Badigannavar
le 19 Déc 2012
I am controlling my simulink models in a for loop from matlab script,,so wen i pause the from script,,,its reall not giving values back to workspace,,,,,
Arun Badigannavar
le 19 Déc 2012
HELLO Mr TAB,,,in your screenshot You have added a breakpoint so u r getting the values to workspace,,,
Voir également
Catégories
En savoir plus sur Event Functions dans Help Center et File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Une erreur s'est produite
Impossible de terminer l’action en raison de modifications de la page. Rechargez la page pour voir sa mise à jour.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asie-Pacifique
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
