Search code examples
blockmatlabsimulink

how to create own simulink block ?


Hi

i would to create a simulink block which can do the following operation.

1) subtract input value with standard value untill the error is less than .01.

example

input value = 7,0005. 
standard values = [1,2,3,4,5,6,7,8,9,10] or [1:n] the result would be 7.

i can do it in matlab but i don't know how to do it in simulink.

In Matlab

a = 7,0005 % or any other input value
b = [1:10] % standard value
error = 1;
index = 0;
while error < 0.01
      error = abs(a-b(index+1));
end

outputResult = b(index+1);

please help me .......


Solution

  • You could create a Matlab function. See: http://www.mathworks.co.uk/help/simulink/slref/matlabfunction.html

    Or you can solve it in Simulink by for example a switch, indicating whether it is close to one of your standard numbers (u<11, u>0, abs(mod(u,1)) < 0.05), then round the value if true do whatever you like when not. Modulus is part of the Math Function block.