필터 지우기
필터 지우기

[Simulink/Matlab] How to access variable from M-file?

조회 수: 1 (최근 30일)
Natt
Natt 2011년 10월 3일
Greetings!
I created a model that does channel coding and it employs bpsk and channel repetition.
I have 3 variables that are inputs. snr, rep, frame_size
Where snr is signal to noise ratio, rep is number of repetitions, and frame_size is, well, the frame_size. This isn't really important but figured I would paint a picture...
I want to perform an analysis where I try to find the bit error rate (ber) while varrying the signal to noise ratio and repetitions--for each frame size.
From the command line, I set the snr, rep, and frame_size. Let's say my model is called channel_coding, I then run sim('channel_coding').
Low and behold ber pops up because it is set to go to the workspace as a variable called ber in the model.
So, I want to write a little script that collects all of this data while varying the parameters I mentioned. However, if I set the variable in the m-file, the model doesn't know and if I set the variable at the command line the m-file doesn't know but the model does.
I have tried making the variables snr, rep, and frame_size 'global'. That didn't work.
I also tried using simset() and that didn't work.
So, my friends. Would someone please share with me this secret that the bowels of the internet is hiding from me?
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2011년 10월 3일
What is "Low and behold ber pops up"?
Natt
Natt 2011년 10월 3일
@Fangjun Jiang
1) "How are the three variables snr, rep and frame_size used in the model? Are they used by any blocks as parameters?"
--snr: snr is used as the signal to noise ratio value in the AWGN block
--rep: rep is used as the number of times to repeat each bit (for repetition coding) in a custom subsystem block
--frame_size: frame_size is used as the parameter for the Bernoulli binary generator
So, before I run my model, I set each of these variable values in the base workspace.
2) What is "Low and behold ber pops up"?
ber: ber is the 1x3 row vector that is the output of the error rate calculation.
In a clean workspace, with only snr, rep, and frame_size set, ber is the output to the workspace after the model runs.

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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 10월 4일
In that case, I don't see any reason why you can't run the following script, just an example:
all_snr=rand(10,1);
all_rep=1:10;
all_frame_size=10:10:100;
result=zeros(10,3);
for k=1:10
snr=all_snr(k);
rep=all_rep(k);
frame_size=all_frame_size(k);
sim('channel_coding');
result(k,:)=ber;
end
  댓글 수: 12
Natt
Natt 2011년 10월 4일
@Kaustubha Govind
That's the ticket! Thanks!
Fangjun Jiang
Fangjun Jiang 2011년 10월 4일
Use simset() is a better solution if your MATLAB version support that. Try to use that as much as you can. Then you don't need to change from M-function to M-script anymore.

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

카테고리

Help CenterFile Exchange에서 Test and Measurement에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by