errors in matlab function block in simulink

i am trying to create a matlab function block in the Simulink that generates square pulses as pulse generator but errors appear please help , I attached screenshots.
<<
>>

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日

0 投票

Your code is not correct. Plus, generating a puls train with Matlab function is not a good idea. You have to know that your Matlab function block, the way it's programmed, will outpu,t each sample time, an entire array.
You can generate such signal with from file block, from worksapce block or using repeated sequence
If you want to use from file block
Fs=1e+9
tend=10*4e-6
t=0:1/Fs:tend;
pulsewidth=1e-6
pulseperiods=(0:10)*4e-6
x=pulstran(t,pulseperiods,'rectpuls',pulsewidth)
v=[t;x];
save yourfile v
Then set the name "yourfile" in the frome file block

28 件のコメント

mohamed samhy
mohamed samhy 2016 年 4 月 11 日
should I write your code in the matlab function block or where please clarify ? ( and thanks for helping really appreciate it )
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日
No, in a script, or Windows Command. The aim is to create the file that contains your signal.
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
I saved it by this name , how should I implement it now in the Simulink block ?
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日
Another way is to use repeating sequence block set the x variable to your block
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
編集済み: mohamed samhy 2016 年 4 月 11 日
that error appears and no o/p
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日
What error?
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
and the scope shows no square pulses , sorry for disturbance I really appreciate your helping
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日
In model configuration parameters set the solver to discret. and set the stop time to tend
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
I adjusted the solver to discrete but I cant find how to set the stop time
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
I found the stop time you mean I adjust it to ( 10 ) ? I will try now
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日
no, set it to tend. because your frequency is very high 1e9. If you want to see quickly your pulse train, set the stop time to t(end) or tend
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
編集済み: mohamed samhy 2016 年 4 月 11 日
it shows error because tend it is very big and maximum is 200000
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日
Do you know what is tend?
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日
From your code:
tend=10*4e-6
How now it's equal to 200000?
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
編集済み: mohamed samhy 2016 年 4 月 11 日
yes the period of my square train pulse which is 4 microseconds
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
編集済み: mohamed samhy 2016 年 4 月 11 日
sorry this was shown to me not 20000
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
thanks for help I just failed to do it and I exhausted you thanks again
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日
編集済み: Azzi Abdelmalek 2016 年 4 月 11 日
Have you read my previous comment? probably you have cleared the variable tend. before running your simulink model you need to set the variable tend to its original value
tend=10*4e-6
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
u mean from the variables in the matlab , ohh I thout Simulink is isolated from matlab . I will try now
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
I tried again same error , I got exhausted seems I cant do it , if u can send me a file I would really appreciate it , thanks again for all.
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日
here the attached mat file
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
I have a problem in the Simulink model if u please lastly can send it to me , my attached file is same as yours because I did it by your step but the Simulink is hard to run without errors. thanks so much so far
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
https://www.dropbox.com/s/a5dlpl56eoohbhf/matfunc.zip?dl=0 this my Simulink file if u can attach your file and see what error appear that will be so helpful , thanks
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 12 日
Here a simulink model
mohamed samhy
mohamed samhy 2016 年 4 月 15 日
編集済み: mohamed samhy 2016 年 4 月 15 日
it did work ,man you are such a great helpful person hope u have a happy life for helping people so much . thanks again man :)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

質問済み:

2016 年 4 月 11 日

編集済み:

2016 年 4 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by