Error in "horzcat" when using matlabFunction to generate file from symbolic expessions
2 次查看(过去 30 天)
显示 更早的评论
I am trying to generate a matlab function script to calculate the dynamics of a 4-link robot manipulator. All calculations are done symbolically without error. The goal is to make the function take a bunch of parameters as an input and return system matrices D,C and G. At the end of the script the function file is generated by the line:
matlabFunction(D,C,G,'File','getDynamicsFnc','Vars',{[q], [q_dot], [I1], [I2], [I3], [I4], [th_a], [DH_params], [m], [com], [g]});
% matlabFunction(D,C,G,'File','getDynamicsFnc','Vars',{q, q_dot, I1, I2, I3, I4, th_a, DH_params, m, com, g});
This leads to the following error:
% Error using horzcat
% Dimensions of arrays being concatenated are not consistent.
% Error in sym/matlabFunction>computeVarnames (line 902)
% allNames = matlab.lang.makeUniqueStrings([repelem("ft",1,nuOfBlocks-1), "ft" allVars],1:nuOfBlocks-1,namelengthmax);
% Error in sym/matlabFunction>postProcessing (line 826)
% [newFunctionNames, newArgumentName] = computeVarnames(blocks);
% Error in sym/matlabFunction (line 198)
% blocks = postProcessing(blocks);
% Error in generate_func_complete (line 119)
% matlabFunction(D,C,G,'File','getDynamicsFnc','Vars',{[q], [q_dot], [I1], [I2], [I3], [I4], [th_a], [DH_params], [m], [com], [g]});
My inputs to the function are shown here:
dim = 4;
q = sym('q',[dim 1],'real');
q_dot = sym('q_dot',[dim 1],'real');
I1 = sym('I1', [3 3],'real');
I2 = sym('I2', [3 3],'real');
I3 = sym('I3', [3 3],'real');
I4 = sym('I4', [3 3],'real');
I = cell(1,4);
I{1} = I1; I{2} = I2; I{3} = I3; I{4} = I4;
th_a = sym('th_a','real');
DH_params = sym('DH_params', [5 4],'real');
com = sym('com', [5 3],'real');
m = sym('m', [1 dim],'real');
g = sym('g','real');
gvec = [0;0;g];
I have checked dimentions for all vectors/matrices and everything seems to be in order. No errors show up in any calculations. Full script is added as an attachment. Note that running the script as is might take several minutes (mostly due to the matlabFunction call).
0 个评论
回答(1 个)
R
2024-5-8
On executing the attached file generate_func_complete.m, I get the following error:
Unrecognized function or variable 'DH'.
Based on your description, I assume that the function DH is being used to calculate Denavit–Hartenberg parameters.
I implemented the function DH (script attached with the answer) based on this assumption and am able to execute generate_func_complete.m without any errors. This leads me to believe there was some dimension mismatch in the implementation of the DH function.
Try executing it with the attached script and let me know if it works out!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!