フィルターのクリア

How to create and empty matrix of a given size in a way that is compatible with codegen

7 ビュー (過去 30 日間)
I have a function that is writing to an output matrix (y).
I can create y in the function using:
y = zeros(size(x));
x is a variable size large array and using zeros() is inefficient because it initializes the array with zeros that are then going to be overwritten.
I was wondering if there is a way to do this more efficiently?
I've tried a lot of the options I can find so far but none are compatible with codegen.
Thanks very much, as always,
John
  2 件のコメント
KSSV
KSSV 2022 年 5 月 11 日
You want to initialize and then do what?
John Edwards
John Edwards 2022 年 5 月 11 日
Codegen requires that the size of the array is declared before use so I'd like to declare it and then fill it with the appropriate output values, rather than using the zeros function, which is then overwritten by the output data.
Best,
John

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

採用された回答

Richard McCormack
Richard McCormack 2022 年 5 月 11 日
編集済み: Richard McCormack 2022 年 5 月 11 日
Hi John,
I think coder.nullcopy is what you are looking for:
Be aware that this function is 'unsafe', in the sense that you can access uninitialized memory after using it.
Best,
Richard

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by