How to Imply the Input Array Dimensions to MATLAB Coder

조회 수: 2 (최근 30일)
Royi Avital
Royi Avital 2019년 9월 14일
댓글: Royi Avital 2020년 5월 27일
Assuming I have a simple function in MATLAB:
function [ mG ] = ProcessImage( mI ) %#codegen
mG = edge(mI, 'Sobel', [], 'both');
end
Now, I want to generate a C code from it.
I also want the C code to work on any 2D Image mI. Yet I don't know the size on compile time. So in C it is solved by sending the dimensions of the array as parameters to the function. Something like:
function [ mG ] = ProcessImage( mI, numRows, numCols ) %#codegen
mG = edge(mI, 'Sobel', [], 'both');
end
Now, my question is, how can I tell MATLAB Coder to understand those parametters are the size of the input image?

답변 (1개)

Denis Gurchenkov
Denis Gurchenkov 2019년 9월 17일
The closest you can do, I think, is this:
codegen ProcessImage -args {coder.typeof(uint(0), [Inf Inf]) } -config:lib
This would generate ProcessImage.c that takes an unbounded 2-d array of uint8 as input. Coder would also generate main.c (in the examples folder) that shows how to allocate and initialize the data structure that ProcessImage.c takes as input.
From there, you can write a simple wrapper that takes a pointer and two sizes and produces the emxArray_uint8_T data structure that coder-generated code takes as input. You can set the "canFreeData" to false and then you don't need to copy the actual values, can just copy your pointer into the emx structure.
  댓글 수: 2
Royi Avital
Royi Avital 2020년 4월 21일
I wish there was more elegant option. I want to generate a function with same signature as you'd do in pure C. So send few pointersa to arrays and integers to hint their dimensions.
Royi Avital
Royi Avital 2020년 5월 27일
Dennis, what about the case MATLAB coder doesn't infer the data dimensions correctly in the middle of the code. Is there a way to assist and tell it the data dimensions?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by