I found a solution to the problem, and in the pictures u can see how it is solved. There exists similar discussion on the topic as well in the matlab questions forum, but heres is how i ended up solving the issue:
How to call a function from simulink, using a matlab function block?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello I need youre help. My question is simple and here it goes:
How can i call a matlab function i made from inside a simulink block?
The matlab (Pos_Solve_Allo.m) function looks like this:
function fp = Pos_Solve_Allo(M, F_gen)
%Pos_Solve_Allo.m
lb = [0;0;0;0;0;0;0;0];
ub = [Inf;Inf;inf;Inf;Inf;inf;Inf;Inf]; % lower and upper bounds
% Aeq = [0 1 4/10;1 0 7/5];
% beq = [7/20;2/5];
fp = lsqlin(M,F_gen,[],[],[],[],lb,ub)
end
So inside the function i use lsqlin solver, which cannot be used in matlab function block as is, that is why i included it in the function above.
Inside my matlab function block i call Pos_Solve_Allo in the following way:
function fp = fcn(m)
% Konstants
a = (1/2 + 1/sqrt(12));
b = (1/2 - 1/sqrt(12));
c = (1/sqrt(3));
P = 1/sqrt(3)*[1 -1 1 -1 1 -1 1 -1;
1 1 -1 -1 1 1 -1 -1;
1 1 1 1 -1 -1 -1 -1];
X=[-a b -b a a -b b -a;
b a -a -b -b -a a b;
c -c -c c c -c -c c];
M = [X;cross(P,X)]
F_gen = transpose([0 0 9.8*m 0 0 0]);
Pos_Solve_Allo(M,F_gen) %Here I call the function
end
However i get the following error:
Function 'lsqlin' not supported for code generation.
Function 'Pos_Solve_Allo.m' (#592.199.232), line 7, column 6: "lsqlin(M,F_gen,[],[],[],[],lb,ub)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed.
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!