Matrix extension in Simulink Embedded doesn't work, in Workspace does

1 回表示 (過去 30 日間)
Vladimir
Vladimir 2011 年 2 月 21 日
Hi,
I have a simple question. I need in Embedded Matlab Function in Simulink run something like this:
Z = ones(15);
for i=16:1:20
for j=16:1:20
Z(i,j) = 0;
end;
end;
x = Z + ones(20);
This code doesn't work in Embedded Matlab Function. The error is: Size mismatch (size [15 x 15] ~= size [20 x 20]).
But if I try the same code run in Workspace, it works normally.
I don't know why. Is there any way or how can I do that in Embedded without the error?
Thanks a lot :-)
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 2 月 22 日
By the way: instead of the loop, you could just use Z(20,20) = 0 to extend the matrix to 20 x 20 with 0's in all new positions (and explicitly set at that one position.)
This will not solve the problem of not being able to extend matrices in embedded Matlab before 2010b though.

サインインしてコメントする。

採用された回答

Kaustubha Govind
Kaustubha Govind 2011 年 2 月 22 日
In versions older than R2010b, you cannot dynamically extend the size of a matrix in Embedded MATLAB. Therefore, you will need to pre-allocate the memory for Z:
Z = ones(20);
for i=16:1:20
for j=16:1:20
Z(i,j) = 0;
end;
end;
x = Z + ones(20);
Starting R2010b, Embedded MATLAB supports dynamic memory allocation using the eml.varsize directive. See the documentation for more details.

その他の回答 (1 件)

Yucel
Yucel 2011 年 2 月 22 日
Embedded should have "if" conditions,otherwise there can be problems like you had.
  1 件のコメント
Vladimir
Vladimir 2011 年 2 月 22 日
I'm sorry, but I haven't understood your response exactly. Could you provide me some brief example, please?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by