필터 지우기
필터 지우기

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

조회 수: 10 (최근 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
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 CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by