m-file code to simulink block

Hi all, I have a m-file code and I would like to transfer the m-file code to a simulink block as a source. Can anyone help me?

3 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 23 日
編集済み: Azzi Abdelmalek 2013 年 2 月 23 日
Can you explain? What is in your m-file
Fang
Fang 2013 年 2 月 23 日
Calculates angle eta with range dependent formulas - counting loop
for i=1:(ae-a0)/sw;
alpha(i)= sw*i;
if (alpha(i)<alpha1)
eta (i) = alpha(i)+gamma;
elseif (alpha(i)<alpha2)
eta (i) = alpha(i)-gamma;
elseif (alpha(i)<alpha3)
eta (i) = alpha(i)+gamma-180;
elseif (alpha(i)<alpha4) % Region IV
eta (i) = alpha(i)-gamma-180;
else % Region V
eta (i) = alpha(i)+gamma-360;
end
end
Calculation of the vertical and horizontal distance
Va = sin(eta.*pi/180)*d;
Ha = d-cos(eta.*pi/180)*d;
Calculation of the length
L = sqrt(Va.^2+(Ha+a).^2);
Calculating the length of the delta d_L
for i=1:(ae-a0)/sw
if (i<2)
d_L (i) = L (i)-L(720); % Bereich I
else
d_L (i)= L(i)-L(i-1);
end
end
Eliminating d_L at the positions of cracks
for i=1:(ae-a0)/sw
if (d_L(i)<0)
d_L (i) = d_L(i-1); % Bereich I
end
end
Calculation of the speed
v = (((d_L./1000).*n)./60).*720;
beta=beta;
Plot the Graph
figure; plot(alpha,v); xlabel('rotation angle Alpha [°]');ylabel('wire speed [m/s]');
title('wire speed vs Angle of roation'), grid on;
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 23 日
編集済み: Azzi Abdelmalek 2013 年 2 月 23 日
What do you want to be your source?

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

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 23 日
編集済み: Azzi Abdelmalek 2013 年 2 月 23 日

0 投票

If you have calculated a signal with your m-file, you can save it in a mat-file, then use a from file block. Specify what do you want to be your source.
t=0:0.1:10
v=sin(t) % The speed
tv=[t;v]
save filename tv

13 件のコメント

Fang
Fang 2013 年 2 月 23 日
the calculated speed and the graph
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 23 日
編集済み: Azzi Abdelmalek 2013 年 2 月 23 日
Ok, the graph can't be a source. We need a speed v and the time t. For example, if
t=0:0.1:10
v=sin(t) % The speed
tv=[t;v]
save filename tv
% In your Simulink model use a from file block (in Simulink/Sources) and set the file name to filename
Fang
Fang 2013 年 2 月 23 日
I save the variable velocity to the .mat file however I got an error when using the from file block. is it because of the for loop or if else command that coz this problem? like too much data?
Error encountered in block 'untitled/From File'
Caused by: Simulink does not support loading the input data in file 'Velocity.mat'. For data saved using MAT file versions prior to 7.3, Simulink can only load two-dimensional arrays consisting of one-dimensional, double, noncomplex samples. To load data of any other type, complexity or dimension, use a timeseries object and save the file using MAT file version 7.3 or later. For example, use: 'save file_name -v7.3 timeseries_object'.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 23 日
編集済み: Azzi Abdelmalek 2013 年 2 月 23 日
Show how did you saved your data in your mat file, and what version of matlab are you using?
Fang
Fang 2013 年 2 月 23 日
save Velocity v;
and im using MATLAB R2012b
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 23 日
編集済み: Azzi Abdelmalek 2013 年 2 月 23 日
No , you did not read my answer. I said you must save time and speed in one array.
t=0:0.1:10
v=sin(t) % The speed
tv=[t;v]
save Velocity tv
Fang
Fang 2013 年 2 月 23 日
編集済み: Azzi Abdelmalek 2013 年 2 月 23 日
It worked now however there is a new error: ''Time values must be monotonically non-decreasing''
tv =[d_L;v]
save Velocity tv;
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 23 日
編集済み: Azzi Abdelmalek 2013 年 2 月 23 日
What is d_L ? it should represent a time
A source signal means two variables: time and the values of your signal at each step time
Fang
Fang 2013 年 2 月 23 日
My project is about the coil winding process.
I have a constant n(60 rev/min) and d_L basically the variable have changes at different angle as the bobbin rotate.
my end result will be the velocity vs the rotation angle not depending on time.
for i=1:(ae-a0)/sw
if (i<2)
d_L (i) = L (i)-L(720);
else
d_L (i)= L(i)-L(i-1);
end
end
v = (((d_L./1000).*n)./60).*720;
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 23 日
Ok, How will you use this in Simulink as a source?
Fang
Fang 2013 年 2 月 23 日
I have no experience with matlab and simulink at all. Only the matlab code was given to me and I was asked to use the result as a source and make a simulink model from it. Do you have any suggestions on how to go about this task? and help would be appreciated.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 23 日
編集済み: Azzi Abdelmalek 2013 年 2 月 23 日
You should read the basics of Matlab and Simulink. You can't get help like this.
Fang
Fang 2013 年 2 月 23 日
alright then. Thanks for the patience and help. =)

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

カテゴリ

質問済み:

2013 年 2 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by