How can I write a better script for a summing block using the 'MATHLAB FUNCTION block'
Show older comments
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 Comment
Birdman
on 28 Mar 2018
Can you share your model?
Answers (0)
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!