How to define the size of output in subfunctions, for C coder

1 visualización (últimos 30 días)
PatrizioGraziosi
PatrizioGraziosi el 30 de Dic. de 2020
Comentada: Ryan Livingston el 1 de En. de 2021
Hello everybody,
I am experiencing an issue when porting a function to C with Matlab coder.
I have a function which runs inside a parfor parallel loop like
output = myfunction(id, mystruct) ;
where id is the parfor index and mystruct an input structure with one dimensional fields which are 1xn arrays, where n is variable.
inside myfunction there is a subfunction which is called inside myfunction like
output_temp = mysubfunction(mystruct.field)
where output_temp is a 1x1 variable.
Everything works in Matlab.
When I build code to port the function in C with Matlab coder, I get the following issue.
I define the input mystruct.field as unbound :1x:Inf, but at the "check for issues" stage, in the mysubfunction the coder sees mystruct.field as :Infx:Inf so that the coder sees output_temp as :1x:Inf instead of 1x1, and this generates an error. I am run out of ideas and cannot fix this...
Can you help me in fixing this, please?
Thanks in advance,
Patrizio
  9 comentarios
PatrizioGraziosi
PatrizioGraziosi el 31 de Dic. de 2020
Editada: PatrizioGraziosi el 31 de Dic. de 2020
Hi Ryan,
I think I got a clue. The issue that I detected was due to the variable 'I', which can be a 1D array but inside the local function only a scalar is entered, so inside the local function I modified as follows
one_over_tau_temp_array = Inf(1,size(vf_x,2));
one_over_tau_temp_array(1,:) = z .* Skk * I(1) * DOSf/e .* (1-vf_x./v_x_k);
Then I got the same error as you, but it was located after processing the results as I was summing a 2D varable 'V',
sum(sum( V ))
whereas I understand it is necessary to specify the sum dimensions like
sum(sum( V, 1), 2).
Now the specific local function looks fine, I'll implement this finding to all the local functions and I'll see...
I'm grateful to you for having accompained me in debugging my file, thank you so much!!!
I wish you a happy new year,
Patrizio
Ryan Livingston
Ryan Livingston el 1 de En. de 2021
Excellent! Happy new year Patrizio!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by