How to create and empty matrix of a given size in a way that is compatible with codegen
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
John Edwards
am 11 Mai 2022
Kommentiert: John Edwards
am 11 Mai 2022
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 Kommentare
Akzeptierte Antwort
Richard McCormack
am 11 Mai 2022
Bearbeitet: Richard McCormack
am 11 Mai 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Function Creation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!