User-defined MATLAB function block in Simulink/Simscape
2 次查看(过去 30 天)
显示 更早的评论
I have imported a set of values for x and y based on a nonlinear curve in a MATLAB function block. I have varying input, t, coming in from a signal builder block and a transformation equation transforming t into x using a constant, k. I would like the function output to be a varying value y based on the input value x = t/k. However, the system does not seem to evaluate the y values when producing an output. I need help defining function h to a value from the y data as a function of x.
function h = fcn(t)
% x = current [Ampere]
% y = power dissipation (heat) [Watt]
% t = torque [Newton * meter]
% h = heat [Watt]
% k = torque constant [Newton * meter / Ampere]
x = [0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10,10.5,11,11.5,12,12.5,13,13.5,14,14.5,15,15.5,16,16.5,17,17.5,18,18.5,19,19.5,20,20.5,21,21.5,22,22.5,23,23.5,24,24.5,25,25.5,26,26.5,27,27.5,28,28.5,29,29.5,30,30.5,31,31.5,32,32.5,33,33.5,34,34.5,35,35.5,36,36.5,37,37.5,38,38.5,39,39.5,40,40.5,41,41.5,42,42.5,43,43.5,44,44.5,45,45.5,46,46.5,47,47.5,48,48.5,49,49.5,50]
y = [0.344,0.527,0.716,0.91,1.11,1.315,1.526,1.742,1.963,2.19,2.422,2.66,2.903,3.152,3.405,3.665,3.929,4.199,4.474,4.755,5.041,5.332,5.628,5.93,6.237,6.549,6.867,7.19,7.518,7.851,8.19,8.533,8.882,9.236,9.596,9.96,10.33,10.705,11.085,11.47,11.86,12.255,12.656,13.061,13.472,13.888,14.308,14.734,15.165,15.601,16.042,16.488,16.939,17.395,17.856,18.322,18.793,19.269,19.75,20.236,20.727,21.223,21.724,22.229,22.74,23.255,23.775,24.301,24.831,25.365,25.905,26.45,26.999,27.553,28.113,28.676,29.245,29.818,30.397,30.98,31.567,32.16,32.757,33.359,33.966,34.577,35.193,35.814,36.439,37.069,37.704,38.343,38.987,39.636,40.289,40.947,41.61,42.277,42.949,43.625,44.306]
k = 0.721;
x = t / k;
h = t;
Currently the output of the function only shows linear values which are equal to the input.
0 个评论
采纳的回答
J Chen
2020-1-30
use a statement like
z = t / k; % don't use x
to get the argument for the table lookup. Then use interp1(x,y,z) to find your output.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!