Effacer les filtres
Effacer les filtres

How can i use the 'mod' function in an Embedded Matlab function?

2 vues (au cours des 30 derniers jours)
Zoltan
Zoltan le 17 Déc 2012
I have the following function. I want to use this algorithm in an embedded Matlab function in simulink.
function y = fcn( u )
y=[0;0;0;0;0;0;0;0;0;0];
newu=0;
nr=0;
s=false;
if u<0 s=true;
end
while u~=0
newu=newu*10+mod(u,10);
u=(u/10);
nr=nr+1;
end;
for i=nr:0
y(i)=mod(newu,10);
newu=(newu/10);
end;
for i=0:nr
y = y+65;
end
end
After compilation it gives me the error :'Function 'mod' is not defined for values of class 'embedded.fi'. 'u'(input value) being of class 'embedded.fi'. What do i have to change to get my output value?
Thank you, Zoli
  15 commentaires
Walter Roberson
Walter Roberson le 19 Déc 2012
Double-check the parity of the line. But even more so, double check how the heck an 8 bit result is generating a negative number below -128, as 8 bit signed values can only be in the range -128 to +127 . Check your scope settings.
Zoltan
Zoltan le 20 Déc 2012
thanks

Connectez-vous pour commenter.

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 17 Déc 2012
Modifié(e) : Azzi Abdelmalek le 17 Déc 2012
In the below part of your code
while u~=0
newu=newu*10+mod(u,10);
u=(u/10);
nr=nr+1;
end;
newu increases rapidly to infinity. that's what causes a problem when
y(i)=mod(newu,10);
  6 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 17 Déc 2012
Modifié(e) : Azzi Abdelmalek le 17 Déc 2012
Yes, but after 309 iterations, 10^309=inf
In the above example, nr=324
Walter Roberson
Walter Roberson le 17 Déc 2012
This is only a problem if the fi object has a representation for infinity and if the input is infinity. Otherwise abs(u) is diminishing in each step and there would be a finite end to the process. It could potentially overflow the buffer of 10 y locations, but that would depend upon the maximum value possible for that particular fi object.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Simulink Environment Customization dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by