Borrar filtros
Borrar filtros

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

10 visualizaciones (últimos 30 días)
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 comentarios
John Edwards
John Edwards el 11 de Mayo de 2022
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

Iniciar sesión para comentar.

Respuesta aceptada

Richard McCormack
Richard McCormack el 11 de Mayo de 2022
Editada: Richard McCormack el 11 de Mayo de 2022
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

Más respuestas (0)

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by