How can I write a better script for a summing block using the 'MATHLAB FUNCTION block'
Afficher commentaires plus anciens
I am trying to replicate the operation of a 'summing block' with a 'function block'. I've read the documentation ( https://www.mathworks.com/help/simulink/slref/subtract.html = scroll to the bottom end) and it says that the summing block reorders the inputs, greatest number first and then adding them. I wrote a script that reorders three inputs and adds them. With integer values, it works. When I sum the results from transfer functions' outputs into the adder I designed, the result is not correct.
Below I posted the script I wrote. I would appreciate if someone finds a better solution for this, Thanks in advance
function y = fcnAdd(inp1,inp2,inp3)
y=0;
if((inp1 > inp2)&&( inp2 > inp3))
y = inp1+inp2+inp3;
end
if((inp1 > inp3)&&(inp3 > inp2))
y = inp1+inp3+inp2;
end
if((inp2 > inp1)&&(inp1 > inp3))
y = inp2+inp1+inp3;
end
if((inp2 > inp3)&&(inp3 > inp1))
y = inp2+inp3+inp1;
end
if((inp3 > inp1)&&(inp1 > inp2))
y = inp3+inp1+inp2;
end
if((inp3 > inp2)&&(inp2 > inp1))
y = inp3+inp2+inp1;
end
if ((inp1 == inp2)&&(inp2 == inp3)&&(inp1 == inp3))
y = inp1+inp2+inp3;
end
1 commentaire
Birdman
le 28 Mar 2018
Can you share your model?
Réponses (0)
Catégories
En savoir plus sur Cell Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!