Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining Variable-size input data for Matlab Coder

I'm trying to generate a mex code file from the .m file using Matlab coder. The code for which is

function [result,x]=tesrank(A,x)

result = [];
n = x;
for col= 1:n
   result = [result, sum(A==col, 2)];
end

For fixed size, I'm able to get it using

codegen tesrank -args {zeros(2,3), zeros(1)}
% Here size(A)=2x3 and size(x)=1x1

How do I do it without limiting the size of A and x?

like image 595
Zero Avatar asked Nov 25 '25 14:11

Zero


1 Answers

You do not have to limit the size of the array A.

Check this example (using Matlab 2014a):

codegen('funcAccumarray1D_max.m', ...
    '-report', ...
    '-args', {coder.typeof(double(0), [Inf 1]), ...
              coder.typeof(double(0), [Inf 1])}, ...
    '-o', 'funcAccumarray1D_max')

for this function:

function [ outs ] = funcAccumarray1D_max(subs, vals, sz) 
%FUNCACCUMARRAY1D_MAX Construct an array by accumulation using 'max'
%#codegen
outs = NaN(sz, 1, 'like', vals);
for ix=1:size(subs,1)
  sub = subs(ix);
  outs(sub,1) = max(outs(sub,1), vals(ix,1));
end
end
like image 136
Jens Henrik Göbbert Avatar answered Nov 28 '25 05:11

Jens Henrik Göbbert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!