Asked by tensorisation
on 30 Aug 2019

I'm struggling to make a mex file work properly (see more here) so I decided to try and use Matlab Coder to do that hoping that would help. Using Matlab Coder I need to define the inputs, but I encountered 2 issues:

- How do I define a variable to be 3 dimensional array (the only options I see there are: scalar, vector or matrix)?
- How do I define an array with dimensions equal to a certain variable (that is also an input)?

Additional details:

The Matlab code I'm trying to convert is:

function [V,delta_V_rms,delta_V_abs,delta_V_max] = potentials_evo(L,t_max,N_eff_occ_sites_bounded,i_eff_V_bounded,j_eff_V_bounded,k_eff_V_bounded,system,over_relax_factor,V,delta_V_rms,delta_V_abs,delta_V_max)

% evolution of the potentials %

% note : for the index directions with periodic boundary conditions: index=mod(index-1,L)+1 . for index=index+1 it is mod(index,L)+1 , and for index=index-1 it is mod(index-2,L)+1 %

for t=1:t_max

for q=1:N_eff_occ_sites_bounded % this is set instead of running i=2:(L-1), j=1:L , k=1:L and ending up going over sites that are 0 in our effective system %

i=i_eff_V_bounded(q);

j=j_eff_V_bounded(q);

k=k_eff_V_bounded(q);

V0=V(i,j,k);

V1=( V(i+1,j,k)+V(i-1,j,k)+V(i,mod(j,L)+1,k)+V(i,mod(j-2,L)+1,k)+V(i,j,mod(k,L)+1)+V(i,j,mod(k-2,L)+1) )/( system(i+1,j,k)+system(i-1,j,k)+system(i,mod(j,L)+1,k)+system(i,mod(j-2,L)+1,k)+system(i,j,mod(k,L)+1)+system(i,j,mod(k-2,L)+1) ); % evolving the potential as the average of its occupied neighbors %

V(i,j,k)=V0+(V1-V0)*over_relax_factor; % evolving the potentials in time with the over relaxation factor %

delta_V_rms(t)=delta_V_rms(t)+(V1-V0)^2; % for each t at a given p, we sum over (V1-V0)^2 in order to eventually calculate delta_V_rms_avg %

delta_V_abs(t)=delta_V_abs(t)+abs(V1-V0); % for each t at a given p, we sum over |V1-V0| in order to eventually calculate delta_V_abs_avg %

delta_V_max(t)=max(abs(V1-V0),delta_V_max(t)); % for each t at a given p, we take the max of |V1-V0| from all the sites in order to eventually calculate delta_V_max_avg %

end

end

end

How do I define input for variables like V which is an LxLxL array?

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Adam (view profile)

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/478260-how-to-properly-define-input-types-for-matlab-coder#comment_740628

## tensorisation (view profile)

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/478260-how-to-properly-define-input-types-for-matlab-coder#comment_740650

## Adam (view profile)

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/478260-how-to-properly-define-input-types-for-matlab-coder#comment_740670

## tensorisation (view profile)

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/478260-how-to-properly-define-input-types-for-matlab-coder#comment_740782

## Adam (view profile)

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/478260-how-to-properly-define-input-types-for-matlab-coder#comment_741272

Sign in to comment.