Coder - Subtract vector from matrix, size mismatch error

Although MATLAB supports subtracting a vector from a matrix (as stated here : https://www.mathworks.com/help/matlab/matlab_prog/compatible-array-sizes-for-basic-operations.html ), when I try to generate code using MATLAB coder it gives me size mismatch error.
For example for the following function MATLAB can't generate code:
function C=subtraction()
A=3*ones(4,5);
B=ones(1,5);
C=A-B;
end
What should I do?

 採用された回答

Walter Roberson
Walter Roberson 2019 年 4 月 28 日

3 投票

specifically says that implicit expansion is not supported by Coder at this time.
The option is to use
C = bsxfun(@minus, A, B);

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB Coder についてさらに検索

製品

リリース

R2019a

質問済み:

2019 年 4 月 28 日

編集済み:

2019 年 6 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by