How can I concatenate matrices in an embedded matlab function block in simulink?

3 ビュー (過去 30 日間)
Nawal El Boghdady
Nawal El Boghdady 2013 年 7 月 5 日
回答済み: Mike Hosea 2013 年 11 月 2 日
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
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
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.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by