Specifying Simulink Block Parameters with a For Loop in an m-File

5 views (last 30 days)
Hello,
I have been trying to specify block parameter values in a Simulink file with m-files, but I have encountered some difficulties. The following is the Simulink file I am working with: https://dl.dropbox.com/u/58781962/try_connecting_sim_matlab.mdl
The purpose is to specify the magnitudes and time points of the pulses. I first tried specifying the parameters in a single run. I did a little bit search and found that the numbers for the block parameter values are supposed to be in the form of text strings, but it did not work. https://dl.dropbox.com/u/58781962/calculating_f_embedded_input_string.m
Then I tried directly using numbers, and it worked! https://dl.dropbox.com/u/58781962/calculating_f_embedded_input.m
However, when I tried turning the file into a user-defined function and using a for loop to do multiple runs, error messages showed up:
??? Error using ==> calculating_f at 78 Error evaluating parameter 'Time' in 'try_connecting_sim_matlab/Pulses/Step10_1': Undefined function or method 'tp1' for input arguments of type 'double'.
Error in ==> f_with_loop at 16 f(i)=calculating_f(feet(i,:),tpi);
The unusual thing is that with all the parameters set with the same method, the error message did not show up until Block Step10_1. The other thing is that it looks like a type of 'double' is not accepted here. I turned numbers into strings (file not provided) and ran the code again but it still did not work.
Could anybody shed some light on this? Any suggestions would be much appreciated!
Best, Chia-Hung

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 6 Sep 2012
there is a problem in this line
set_param('try_connecting_sim_matlab/Pulses/Step1_1','Time','tp1(1)')
use: num2str(tp1(1)) instead 'tp1(1)'
set_param('try_connecting_sim_matlab/Pulses/Step1_1','Time',num2str(tp1(1)))
  2 Comments
Chia-Hung Tsai
Chia-Hung Tsai on 6 Sep 2012
Hi Azzi,
It worked!!! I did not know the single quotation mark would give such a difference. Thank you very much!!!
Best,
Chia-Hung

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!