[Simulink/Matlab] How to access variable from M-file?
11 views (last 30 days)
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?
Fangjun Jiang on 4 Oct 2011
In that case, I don't see any reason why you can't run the following script, just an example: