Error in port widths or dimensions
Ältere Kommentare anzeigen
Hi, I do get the following error:
Caused by:
Error using sldebugui (line 77)
Errors occurred during parsing of MATLAB function 'Line force/MATLAB
Function'(#229)
Error using sldebugui (line 77)
Error in port widths or dimensions. Output port 1 of 'Ceto5_model_028/Line force/MATLAB Function/x' is a one dimensional vector with 1 elements.
My matlab embedded function is the following:
function [Fx, Fz, M, alpha1, alpha2] = Line(x, z, beta, xo, zo, k, x_ba, z_ba) %#codegen
lo = ((xo-x_ba)^2+(zo+z_ba)^2)^0.5;
zb1 = z + z_ba*cos(beta) + x_ba*sin(beta); zb2 = z + z_ba*cos(beta) - x_ba*sin(beta); xb1 = x - x_ba*cos(beta) + z_ba*sin(beta); xb2 = x + x_ba*cos(beta) + z_ba*sin(beta);
alpha1 = atan2(xb1,zb1); alpha2 = atan2(2*x0-xb2,zb2);
l1 = sin(alpha1)*zb1; l2 = sin(alpha2)*zb2;
F1 = max(0,k*(l1-lo)); F2 = max(0,k*(l2-lo));
Fx1 = -F1*cos(alpha1); Fx2 = F2*cos(alpha2); Fz1 = -2*F1*sin(alpha1); Fz2 = -2*F2*sin(alpha2);
Fx = Fx1 + Fx2; Fz = Fz1 + Fz2; M = Fx1*(zb1-z) - Fz1*(xb1-x) + Fx2*(zb2-z) - Fz2*(xb2-x);
My input x is just a single value, I'm not sure why I get this error, can anyone help? Thanks Alex
2 Kommentare
Mike Hosea
am 15 Sep. 2014
Bearbeitet: Mike Hosea
am 15 Sep. 2014
Formatting the code for easier reading:
function [Fx, Fz, M, alpha1, alpha2] = Line(x, z, beta, xo, zo, k, x_ba, z_ba) %#codegen
lo = ((xo-x_ba)^2+(zo+z_ba)^2)^0.5;
zb1 = z + z_ba*cos(beta) + x_ba*sin(beta);
zb2 = z + z_ba*cos(beta) - x_ba*sin(beta);
xb1 = x - x_ba*cos(beta) + z_ba*sin(beta);
xb2 = x + x_ba*cos(beta) + z_ba*sin(beta);
alpha1 = atan2(xb1,zb1);
alpha2 = atan2(2*x0-xb2,zb2);
l1 = sin(alpha1)*zb1;
l2 = sin(alpha2)*zb2;
F1 = max(0,k*(l1-lo));
F2 = max(0,k*(l2-lo));
Fx1 = -F1*cos(alpha1);
Fx2 = F2*cos(alpha2);
Fz1 = -2*F1*sin(alpha1);
Fz2 = -2*F2*sin(alpha2);
Fx = Fx1 + Fx2;
Fz = Fz1 + Fz2;
M = Fx1*(zb1-z) - Fz1*(xb1-x) + Fx2*(zb2-z) - Fz2*(xb2-x);
Image Analyst
am 15 Sep. 2014
Exactly which of those lines is line #77. Also it's not a good idea to name your own functions after built in MATLAB functions like line(). True, MATLAB is case sensitive and Line() is different than line() but nonetheless it's not a good idea.
Akzeptierte Antwort
Weitere Antworten (1)
Alexandre
am 15 Sep. 2014
0 Stimmen
2 Kommentare
Image Analyst
am 15 Sep. 2014
It's bizarre though that you got the error message you did instead of the one Mike got. Weird.
Mike Hosea
am 15 Sep. 2014
Bearbeitet: Mike Hosea
am 15 Sep. 2014
Although we encourage people to test their code in MATLAB, a lot of code gets written for the MATLAB Function Block that never gets run in MATLAB. Often the compiler will issue a similar error to what would have been encountered in interpreted mode. I think the error was probably reported in this case, too, but the Simulink error was the first error, and most of us have been trained by experience to deal with the first error first, since at some point after that, compilers tend to generate spurious "downstream" errors. In this case, unfortunately, the Simulink error is actually a "downstream" error, so we'll have to take some of the blame here. :) Consequently, I have just created a bug report for this, although I'm not sure we will be able to fix this without creating some other problem in a different situation.
Kategorien
Mehr zu Reporting and Database Access finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!