How can I concatenate matrices in an embedded matlab function block in simulink?
2 次查看(过去 30 天)
显示 更早的评论
Hey all;
I wanted to concatenate matrices together in an embedded matlab function block, so i'd like to do something like this:
s.a = [s.a , b];
'a' is a 22x1 matrix, 'b' is also a 22x1 matrix, so in the end i'd like 's.a' to be a 22x2 matrix. The syntax above does not work and gives the following error:
================ Size mismatch (size [22 x 1] ~= size [22 x 2]). The size to the left is the size of the left-hand side of the assignment ================
I tried deleting the field 'a' and then re-adding it again after modifications using the 'remfield' and 'setfield' commands accordingly. However, the 'remfield' command is not supported by code generation, which is what I need in order to run my model on the xPC real-time target machine. Any ideas how I might fix this? Thanks in advance :)
1 个评论
Kaustubha Govind
2013-7-10
Typically, you cannot change the size of a variable dynamically inside the MATLAB Function block, since this is not code-generation compatible (the block always generate C code from the MATLAB code for execution). You need to declare variables as variable-size using coder.varsize to allow such constructs.
回答(1 个)
Mike Hosea
2013-11-2
Kaustubha's comment is the answer to this question. Use coder.varsize to give s.a the variable-size properties that you need. For example, if you want to be able to concatenate up to 10 columns, then you could declare
coder.varsize('s.a',[22,10],[0,1]);
or use Inf instead of 10 if you don't know how many columns will be required. That particular coder.varsize line specifies that the number of rows, 22, is not variable.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!