Programatically changing block parameter during simulation.

조회 수: 1 (최근 30일)
Janez
Janez 2012년 8월 23일
I am automatically changing the amplitude value of my sin wave block in my model. But the problem is that my program runs the simulation multiple times and do not change the values of amplitude during one simulation. this is the code:
amplitude_vec=(0.5:0.2:2.3);
for i=1:10
amplitude=amplitude_vec(i);
sim('Amplifier.mdl');
end;
How do i write a program that will change the values of amplitude of my sin wave block in one simulation run ?
Thanks for your help,
Janez
  댓글 수: 2
TAB
TAB 2012년 8월 23일
편집: TAB 2012년 8월 23일
"my program runs the simulation multiple times and do not change the values of amplitude during one simulation"...??? Confusing line.
You have never changed any block parameter value in existing code.
Janez
Janez 2012년 8월 23일
편집: Janez 2012년 8월 23일
yes i did.
Here : amplitude=amplitude_vec(i);
This changes the amplitude parameter of the sine wave. I placed variable 'amplitude' in that block.
This changes the amplitude of the sine wave for every simulation. Which means that my program runs ten simulation each with different sine wave amplitude. Believe me, i have run it.
But i want it to happen in one simulation for different time intervals in that simulation.

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 25일
편집: Azzi Abdelmalek 2012년 8월 26일
amplitude_vec=(0.5:0.2:2.3);
for k=1:10
amplitude=amplitude_vec(k);
set_param('Amplifier/Sine Wave','Amplitude',num2str(amplitude))
%check if "Sine Wave" is the name of your sine block, if not, replace it
sim('Amplifier');
end;
or you can use (you don't need to pause simulation)
  1. the below code allows to create a signal with multiple amplitude saved in "file.mat"
  2. you set sine amplitude to 1
amplitude_vec=(0.5:0.2:2.3);
t0=0;tf=5;te=0.1;
tf1=tf;t=[];amp=[];
for k=1:length(amplitude_vec)
t1=t0:te:tf;
t=[t t1 ];
amp=[ amp amplitude_vec(k)*ones(1,length(t1))];
t0=tf+te;tf=t0+tf1
end
close;plot(t,amp);
ty=[t;amp];
save file ty
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 26일
편집: Azzi Abdelmalek 2012년 8월 26일
you can use the "assertion" block to pause your simulation
Janez
Janez 2012년 8월 27일
Hey
This last part works like a charm. Thank you.
Best regards.

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

추가 답변 (1개)

Mariano Lizarraga
Mariano Lizarraga 2012년 8월 25일
편집: Mariano Lizarraga 2012년 8월 25일
I might be misunderstanding your problem statement but if you only want to change the amplitude base on the time of the simualtion then you could do an embedded matlab function as follows:
function y = timeDependentSine(t, amplitude, freq, phase, bias)
y = amplitude*sin(freq*t + phase) + bias;
and now all the parameters for the sine function can be time varying if you so desire. You can implement all in Simulink as shown here: http://skit.ch/nwn1

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by