how to assign values in for loop to a matrix in matlab function block?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Chamith Jayasinghe
le 22 Avr 2016
Commenté : Chamith Jayasinghe
le 25 Avr 2016
Hi, I have following code ,
N = 400; phi = []; for kk = 1:5 phi = [phi; exp(j*2*pi*(kk/N)*(0:N-1))]; end
I need to create 5 x 400 matrix for phi. I'm using this code in a matlab function block. but I'm getting a size mismatch error. any ideas?
0 commentaires
Réponse acceptée
Stefan Raab
le 23 Avr 2016
Hello,
the MATLAB Function block has limitations due to code generation. Either you preallocate the memory for phi and assign it as a comlex variable in the first definition, or you write an external "normal" MATLAB function that you call from inside the MATLAB Function block. The latter will then only work if you define your normal function as extrinsic inside the MF block (doc coder.extrinsic). This will work fine in a simulation, but if you want to generate code from the Simulink model, the coder.extrinsic won't work anymore.
Here is a sample code for the first option:
N = 400;
phi = 1i*ones(5,400);
for kk = 1:5
phi(kk,:) = exp(1j*2*pi*(kk/N)*(0:N-1));
end
This worked for me. I hope this might help you.
Kind regards, Stefan
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Simulink Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!